aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-02-15 18:37:37 +0000
committerGitHub <noreply@github.com>2021-02-15 18:37:37 +0000
commitc04266c0be5183a05cbca47bb01a30ed4eb4f941 (patch)
tree04024be774bad43b9d08b53faee04acfa16071ca
parentdce97aa1d2a12e5aa388b0c948ef74a0bfb9f628 (diff)
parenta5450db5d72293945e7f430c88c3aa5b726ba824 (diff)
downloadperlweeklychallenge-club-c04266c0be5183a05cbca47bb01a30ed4eb4f941.tar.gz
perlweeklychallenge-club-c04266c0be5183a05cbca47bb01a30ed4eb4f941.tar.bz2
perlweeklychallenge-club-c04266c0be5183a05cbca47bb01a30ed4eb4f941.zip
Merge pull request #3527 from stuart-little/stuart-little_100_raku
1st commit on 100_raku
-rwxr-xr-xchallenge-100/stuart-little/raku/ch-1.p616
-rwxr-xr-xchallenge-100/stuart-little/raku/ch-2.p625
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