Skip to content

Instantly share code, notes, and snippets.

@mcmillhj mcmillhj/seq.p6
Created Apr 27, 2018

What would you like to do?
Why does this return a Seq? I expected a List.
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
You can’t perform that action at this time.