aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-07-19 08:57:48 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-07-19 08:57:48 -0400
commit46dff9df03baeb479313adb7038afc530c32426b (patch)
treef8c6284282c05db27832c9471d1771ddc02ef0f5
parent675c4ed9a3b441729b9558c051638027242ba77a (diff)
downloadperlweeklychallenge-club-46dff9df03baeb479313adb7038afc530c32426b.tar.gz
perlweeklychallenge-club-46dff9df03baeb479313adb7038afc530c32426b.tar.bz2
perlweeklychallenge-club-46dff9df03baeb479313adb7038afc530c32426b.zip
1st commit on 122_perl
-rwxr-xr-xchallenge-122/stuart-little/perl/ch-1.pl19
-rwxr-xr-xchallenge-122/stuart-little/perl/ch-2.pl29
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-122/stuart-little/perl/ch-1.pl b/challenge-122/stuart-little/perl/ch-1.pl
new file mode 100755
index 0000000000..2282d8e905
--- /dev/null
+++ b/challenge-122/stuart-little/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <space-separated numbers> <space-separated numbers>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use List::Util qw(reduce zip);
+
+sub runAvg($aref) {
+ my @ar = zip [1..scalar @{$aref}], $aref;
+ my $res = reduce { my @a = @{$a}; push @a, ($a[-1]*($b->[0]-1)+$b->[1])/$b->[0]; \@a } [0,], @ar;
+ shift @{$res};
+ return $res;
+}
+
+say qq!@{${\ do{runAvg(\@ARGV)}}}!;
diff --git a/challenge-122/stuart-little/perl/ch-2.pl b/challenge-122/stuart-little/perl/ch-2.pl
new file mode 100755
index 0000000000..611a90c3f5
--- /dev/null
+++ b/challenge-122/stuart-little/perl/ch-2.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <score>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+sub comp($nr,$bd) {
+ my $tab=[[[],],];
+ for my $n (1..$nr) {
+ my $item=[];
+ for my $i (1..$bd) {
+ (scalar @{$tab} >= $i) && do {
+ my @suppPrev = map {my @supp = ($i, @{$_}); \@supp} @{$tab->[-$i]};
+ push @{$item}, @suppPrev;
+ };
+ }
+ scalar @{$tab} >= $bd && do { shift @{$tab} };
+ push @{$tab}, $item;
+ }
+ return $tab->[-1];
+}
+
+for (@{comp($ARGV[0],3)}) {
+ say "@{$_}";
+}
+