aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Anderson <mark@andemark.io>2024-08-05 06:47:50 +0000
committerMark Anderson <mark@andemark.io>2024-08-05 06:47:50 +0000
commitf2db6bb45f936cc066baba6828249999c88cc760 (patch)
tree313b85e72c71c3ece2e19529fdb540abf62e80cd
parentadbdc962dea2e0b5b05cbd6b147626de57a31423 (diff)
downloadperlweeklychallenge-club-f2db6bb45f936cc066baba6828249999c88cc760.tar.gz
perlweeklychallenge-club-f2db6bb45f936cc066baba6828249999c88cc760.tar.bz2
perlweeklychallenge-club-f2db6bb45f936cc066baba6828249999c88cc760.zip
Challenge 281 Solutions (Raku)
-rw-r--r--challenge-281/mark-anderson/raku/ch-2.raku16
1 files changed, 7 insertions, 9 deletions
diff --git a/challenge-281/mark-anderson/raku/ch-2.raku b/challenge-281/mark-anderson/raku/ch-2.raku
index 404722c057..88d11a0976 100644
--- a/challenge-281/mark-anderson/raku/ch-2.raku
+++ b/challenge-281/mark-anderson/raku/ch-2.raku
@@ -11,29 +11,27 @@ sub knights-move($start is copy, $end is copy)
$start .= &coordinates;
$end .= &coordinates;
- my $dx := -2, -1, 1, 2, -2, -1, 1, 2;
- my $dy := -1, -2, -2, -1, 1, 2, 2, 1;
+ my $mv := (-2,-1),(-1,-2),(1,-2),(2,-1),(-2,1),(-1,2),(1,2),(2,1);
my @queue;
my @visit;
- @queue.push: { :x($start[0]), :y($start[1]), :dis(0) }
+ @queue.push: { :xy($start), :dis(0) }
@visit[$start[0];$start[1]] = True;
while @queue
{
my %t = shift @queue;
- return %t<dis> if all(%t<x> == $end[0], %t<y> == $end[1]);
+ return %t<dis> if %t<xy> eqv $end;
for ^8
{
- my $x = %t<x> + $dx[$_];
- my $y = %t<y> + $dy[$_];
+ my $xy := %t<xy> >>+<< $mv[$_];
- if all(all($x,$y) ~~ ^8, not @visit[$x;$y])
+ if all(all($xy) ~~ ^8, not @visit[$xy[0];$xy[1]])
{
- @visit[$x;$y] = True;
- @queue.push: { :$x, :$y, :dis(%t<dis> + 1) }
+ @visit[$xy[0];$xy[1]] = True;
+ @queue.push: { :$xy, :dis(%t<dis> + 1) }
}
}
}