aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-06-14 09:11:03 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-06-14 09:11:03 -0400
commit4417de34fbefb43c7d965742541f1020c60a2436 (patch)
tree4c5205762cb13f3a3590ebd91baf1693aec748d3
parentdad6bcabbefc743b091695a82fcfb92342397e38 (diff)
downloadperlweeklychallenge-club-4417de34fbefb43c7d965742541f1020c60a2436.tar.gz
perlweeklychallenge-club-4417de34fbefb43c7d965742541f1020c60a2436.tar.bz2
perlweeklychallenge-club-4417de34fbefb43c7d965742541f1020c60a2436.zip
1st commit on 117_perl
-rwxr-xr-xchallenge-117/stuart-little/perl/ch-1.pl30
-rwxr-xr-xchallenge-117/stuart-little/perl/ch-2.pl28
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-117/stuart-little/perl/ch-1.pl b/challenge-117/stuart-little/perl/ch-1.pl
new file mode 100755
index 0000000000..f2b6e272cf
--- /dev/null
+++ b/challenge-117/stuart-little/perl/ch-1.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <path-to-file>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use File::Slurp qw(read_file);
+use List::AllUtils qw(sum);
+
+my @lines = (scalar @ARGV) ? (read_file($ARGV[0])) : (<DATA>);
+say(((scalar @lines)+1)*((scalar @lines) + 2)/2 - sum map {/^[^\d]*(\d+)/; int($1)} @lines );
+
+__DATA__
+11, Line Eleven
+1, Line one
+9, Line Nine
+13, Line Thirteen
+2, Line two
+6, Line Six
+8, Line Eight
+10, Line Ten
+7, Line Seven
+4, Line Four
+14, Line Fourteen
+3, Line three
+15, Line Fifteen
+5, Line Five
diff --git a/challenge-117/stuart-little/perl/ch-2.pl b/challenge-117/stuart-little/perl/ch-2.pl
new file mode 100755
index 0000000000..d5b144071f
--- /dev/null
+++ b/challenge-117/stuart-little/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <number>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use Math::Cartesian::Product;
+
+my @memo=([''],['R','LH']);
+
+sub mkPaths($size) {
+ ($size > $#memo) && do {
+ my @res = map {'R' . $_} @{mkPaths($size-1)};
+ for my $nr (0..$size-1) {
+ my @gluedPairs = map {'L' . $_->[0] . 'H' . $_->[1]} cartesian {1} mkPaths($nr), mkPaths($size -1 - $nr);
+ push @res, @gluedPairs;
+ }
+ push @memo, \@res;
+ };
+ return $memo[$size];
+}
+
+for (@{mkPaths($ARGV[0])}) {
+ say;
+}