diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-15 20:20:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-15 20:20:35 +0100 |
| commit | d499d2f0336c1c605666703aaea8427f1d4815de (patch) | |
| tree | 54a8cd309928b666d2a48a8f17d4323fca468a34 | |
| parent | b628fcaee12a083f4208818b9c1e4142422f4192 (diff) | |
| parent | 4417de34fbefb43c7d965742541f1020c60a2436 (diff) | |
| download | perlweeklychallenge-club-d499d2f0336c1c605666703aaea8427f1d4815de.tar.gz perlweeklychallenge-club-d499d2f0336c1c605666703aaea8427f1d4815de.tar.bz2 perlweeklychallenge-club-d499d2f0336c1c605666703aaea8427f1d4815de.zip | |
Merge pull request #4257 from stuart-little/stuart-little_117_perl
1st commit on 117_perl
| -rwxr-xr-x | challenge-117/stuart-little/perl/ch-1.pl | 30 | ||||
| -rwxr-xr-x | challenge-117/stuart-little/perl/ch-2.pl | 28 |
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; +} |
