aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-064/mark-anderson/raku/ch-1.raku38
-rw-r--r--challenge-064/mark-anderson/raku/ch-2.raku19
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-064/mark-anderson/raku/ch-1.raku b/challenge-064/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..9620f180a5
--- /dev/null
+++ b/challenge-064/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,38 @@
+#!/usr/bin/env raku
+
+my @matrix = [ 1, 2, 3 ],
+ [ 4, 5, 6 ],
+ [ 7, 8, 9 ];
+
+my $width = @matrix[0].elems;
+my $height = @matrix.elems;
+my $max-steps = $width-1 + $height-1;
+
+my @array = next-step([ ${ x => 0, y => 0, path => [@matrix[0;0]] } ]);
+
+my %sum;
+%sum{.<path>} = .<path>.sum for @array;
+.say for %sum.minpairs;
+
+sub next-step(@array) {
+ my @new;
+ state $steps++;
+
+ for @array -> %hash {
+ if %hash<x>+1 < $width { # go right
+ @new.push: { x => %hash<x>+1,
+ y => %hash<y>,
+ path => [|%hash<path>, @matrix[%hash<y>;%hash<x>+1]] };
+ }
+
+ if %hash<y>+1 < $height { #go down
+ @new.push: { x => %hash<x>,
+ y => %hash<y>+1,
+ path => [|%hash<path>, @matrix[%hash<y>+1;%hash<x>]] };
+ }
+ }
+
+ return @new if $steps == $max-steps;
+
+ next-step(@new);
+}
diff --git a/challenge-064/mark-anderson/raku/ch-2.raku b/challenge-064/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..3a4f28ec3e
--- /dev/null
+++ b/challenge-064/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+
+my $S = "perlweeklychallenge";
+my @W = <weekly challenge perl week>;
+my %H;
+
+for @W -> $w {
+ if $S ~~ /$w/ {
+ %H{$/.from}.push: ~$/;
+ }
+}
+
+if %H.keys == 0 {
+ say "0 as no matching word found";
+}
+
+else {
+ say %H.keys.sort(* <=> *).map({|%H{$_}.sort(*.chars)}).join(", ");
+}