aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2024-11-17 12:55:05 +0100
committerJan Krňávek <Jan.Krnavek@gmail.com>2024-11-17 12:55:05 +0100
commit677731527faf177fb5d4122a35fb2fc44508b6b3 (patch)
treeba81492162dd740e8193671f2c8871efc1b43188
parent660e815a91d4d24fb575eae1d0d0b9cf078295d6 (diff)
downloadperlweeklychallenge-club-677731527faf177fb5d4122a35fb2fc44508b6b3.tar.gz
perlweeklychallenge-club-677731527faf177fb5d4122a35fb2fc44508b6b3.tar.bz2
perlweeklychallenge-club-677731527faf177fb5d4122a35fb2fc44508b6b3.zip
revision jump-game
-rw-r--r--challenge-295/wambash/raku/ch-2.raku13
1 files changed, 5 insertions, 8 deletions
diff --git a/challenge-295/wambash/raku/ch-2.raku b/challenge-295/wambash/raku/ch-2.raku
index b03b37a905..daa0978913 100644
--- a/challenge-295/wambash/raku/ch-2.raku
+++ b/challenge-295/wambash/raku/ch-2.raku
@@ -2,15 +2,12 @@
sub jump ($from, +@ints) {
$from «+« ( 1..@ints[$from] )
- andthen .Slip
}
sub jump-game (+@ints) {
- (0,), { .unique.map: { jump $_, @ints } } ... -> @where { @ints.end ∈ @where }\
- andthen .skip
+ (0,), { .unique.map: { |jump $_, @ints } } ... *
andthen .head: @ints.elems
- andthen .elems
- andthen $_ ≤ @ints.end ?? $_ !! -1
+ andthen .first: -> @where { @ints.end ∈ @where }, :k
}
multi MAIN (Bool :test($)!) {
@@ -20,12 +17,12 @@ multi MAIN (Bool :test($)!) {
is jump( 1, (2,3,1,1,4) ), (2,3,4);
is jump-game(2,3,1,1,4),2;
is jump-game(2,3,0,4),2;
- is jump-game(2,0,0,4),-1;
+ is jump-game(2,0,0,4),Nil;
is jump-game(1,1,1,1,1,1,0),6;
- is jump-game(0,0),-1;
+ is jump-game(0,0),Nil;
done-testing;
}
multi MAIN (+@ints) {
- say jump-game @ints
+ say jump-game( @ints ) // -1
}