aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-08 20:55:02 +0100
committerGitHub <noreply@github.com>2020-06-08 20:55:02 +0100
commita2ec7d80ffafbd445810b586bf4fe3eb1843ea33 (patch)
tree776bfeed93837091b313ea943f5eca4e19acce4a
parent71f760620a5d3d5c1f618fb73895e0f80fa1a56f (diff)
parentd6a315af18d92c9c4ed3741af532555f5e6f5c0e (diff)
downloadperlweeklychallenge-club-a2ec7d80ffafbd445810b586bf4fe3eb1843ea33.tar.gz
perlweeklychallenge-club-a2ec7d80ffafbd445810b586bf4fe3eb1843ea33.tar.bz2
perlweeklychallenge-club-a2ec7d80ffafbd445810b586bf4fe3eb1843ea33.zip
Merge pull request #1805 from andemark/branch-for-challenge-064
Challenge 64 Solutions
-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(", ");
+}