aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-07-20 17:18:21 +0100
committerGitHub <noreply@github.com>2021-07-20 17:18:21 +0100
commit959bf568e982c34c168cf3a2302554ea52a8d7a7 (patch)
tree210b60ed7061e211d39a09b8ca03f524c2dbe7cd
parent86a970671cfbf03beafbe24efcf05173992ae7a2 (diff)
parent46dff9df03baeb479313adb7038afc530c32426b (diff)
downloadperlweeklychallenge-club-959bf568e982c34c168cf3a2302554ea52a8d7a7.tar.gz
perlweeklychallenge-club-959bf568e982c34c168cf3a2302554ea52a8d7a7.tar.bz2
perlweeklychallenge-club-959bf568e982c34c168cf3a2302554ea52a8d7a7.zip
Merge pull request #4560 from stuart-little/stuart-little_122_perl
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 "@{$_}";
+}
+