diff options
| -rwxr-xr-x | challenge-100/stuart-little/raku/ch-1.p6 | 16 | ||||
| -rwxr-xr-x | challenge-100/stuart-little/raku/ch-2.p6 | 25 |
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-100/stuart-little/raku/ch-1.p6 b/challenge-100/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..24c39dac69 --- /dev/null +++ b/challenge-100/stuart-little/raku/ch-1.p6 @@ -0,0 +1,16 @@ +#!/usr/bin/env perl6 +use v6; + +# run <script> <time in format hh:mm[am/pm]; 'am' or 'pm' can be capitalized or surrounded by spaces> + +sub convTime ($time) { + $time ~~ m/(\d+)\:(\d+)(.*)/; + (! $2.Str) && ($0.Int == 0) && return qq|{$0+12}:$1| ~ " am"; + (! $2.Str) && ($0.Int < 12) && return $time ~ " am"; + (! $2.Str) && ($0.Int == 12) && return $time ~ " pm"; + (! $2.Str) && ($0.Int > 12) && return qq|{sprintf("%02d", $0-12)}:$1| ~ " pm"; + $2.Str.lc.contains("am") && return qq|$0:$1|; + $2.Str.lc.contains("pm") && return qq|{$0+12}:$1|; +} + +say convTime(@*ARGS.join); diff --git a/challenge-100/stuart-little/raku/ch-2.p6 b/challenge-100/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..0dbe6a5dd2 --- /dev/null +++ b/challenge-100/stuart-little/raku/ch-2.p6 @@ -0,0 +1,25 @@ +#!/usr/bin/env perl6 +use v6; + +sub redStep(@row1,@row2) { + (Inf,|@row1,Inf).rotor(2 => -1).map(*.min) Z+ @row2 +} + +sub collapseTriang(*@rows) { + @rows.reduce(&redStep).min +} + +say collapseTriang(@*ARGS.map(*.Int).rotor(1..*).map(*.Array).Array) + +=finish + +run <script> <space-separated array entries, left-to-right and top-to-bottom> + +e.g. <script> 1 2 4 6 4 9 5 1 7 2 + +will pass the triangle + + 1 + 2 4 + 6 4 9 + 5 1 7 2 |
