Created
April 27, 2018 14:28
-
-
Save mcmillhj/57a4e81cfbfa94d33bc2babcf4563da1 to your computer and use it in GitHub Desktop.
Why does this return a Seq? I expected a List.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub search(Int $x, Int $y, Int $max-depth is copy = 25000 --> List) { | |
state %cache{Set}; | |
my @queue = (($x, $y, Nil, Nil),); | |
while @queue and --$max-depth > 0 { | |
my ($x, $y, $px, $py) = @queue.shift(); | |
%cache{Set($x, $y)} = [$px, $py]; | |
if $x == $y { | |
my @path; | |
while $x and $y { | |
@path.push: [$x, $y]; | |
($x, $y) = %cache{Set($x, $y)}; | |
} | |
return reverse @path; | |
} | |
else { | |
@queue.push: (2 * $x, $y + 1, $x, $y); | |
@queue.push: ($x + 1, 2 * $y, $x, $y); | |
} | |
} | |
return Nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment