From 677731527faf177fb5d4122a35fb2fc44508b6b3 Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sun, 17 Nov 2024 12:55:05 +0100 Subject: revision jump-game --- challenge-295/wambash/raku/ch-2.raku | 13 +++++-------- 1 file 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 } -- cgit