aboutsummaryrefslogtreecommitdiff
path: root/challenge-117
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-06-19 21:55:16 +0100
committerGitHub <noreply@github.com>2021-06-19 21:55:16 +0100
commit333d899c804d956fd3fdf970af6debbd60f8a6a0 (patch)
treeeb84634d0de3a7deed49cbe648eca714573ef2e0 /challenge-117
parent47c66efb69abbd6d2fa3e0d5c6e4655caa438527 (diff)
parent2f3ade94582c8cb877e9bc079323ad98e356dbff (diff)
downloadperlweeklychallenge-club-333d899c804d956fd3fdf970af6debbd60f8a6a0.tar.gz
perlweeklychallenge-club-333d899c804d956fd3fdf970af6debbd60f8a6a0.tar.bz2
perlweeklychallenge-club-333d899c804d956fd3fdf970af6debbd60f8a6a0.zip
Merge pull request #4292 from wambash/challenge-week-117
solutions week 117
Diffstat (limited to 'challenge-117')
-rw-r--r--challenge-117/wambash/raku/ch-1.raku35
-rw-r--r--challenge-117/wambash/raku/ch-2.raku27
2 files changed, 62 insertions, 0 deletions
diff --git a/challenge-117/wambash/raku/ch-1.raku b/challenge-117/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..92e5a75327
--- /dev/null
+++ b/challenge-117/wambash/raku/ch-1.raku
@@ -0,0 +1,35 @@
+#!/usr/bin/env raku
+
+sub missing-row (@lines, :$expected = 1..15 ) {
+ @lines
+ andthen .map: *.split: ',', 2
+ andthen .map: *.[0].Int
+ andthen $expected ∖ $_
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ my @lines = '
+ 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
+ '.lines;
+
+ is missing-row(@lines), 12;
+ done-testing;
+}
+
+multi MAIN () {
+ put missing-row $*IN.lines
+}
diff --git a/challenge-117/wambash/raku/ch-2.raku b/challenge-117/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..acc86371c3
--- /dev/null
+++ b/challenge-117/wambash/raku/ch-2.raku
@@ -0,0 +1,27 @@
+#!/usr/bin/env raku
+
+sub next-paths ($path) {
+ slip (
+ 'LH' ~ $path,
+ $path ~ 'LH',
+ 'L' ~ $path ~'H',
+ 'R' ~ $path,
+ $path ~ 'R',
+ )
+}
+
+constant @find-possible-paths = '', { .map( *.&next-paths ).unique.cache } ... * ;
+
+multi MAIN ($n) {
+ put @find-possible-paths[$n]
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply next-paths('LH').Set, ('LHLH','LHLH','LLHH','RLH','LHR').Set;
+ is-deeply @find-possible-paths[1].Set, <R LH>.Set;
+ is-deeply @find-possible-paths[2].Set, <RR LHR LHLH LLHH RLH LRH>.Set;
+ is @find-possible-paths.[10].elems, 349526;
+ is @find-possible-paths.[120].head(4), ('LH' x 120, 'L' ~ 'LH' x 119 ~ 'H', 'R' ~ 'LH' x 119, 'LH' x 119 ~ 'R');
+ done-testing;
+}