Skip to content

Instantly share code, notes, and snippets.

Created March 23, 2012 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2173487 to your computer and use it in GitHub Desktop.
Save anonymous/2173487 to your computer and use it in GitHub Desktop.
pmichaud@kiwi:~/p6/rakudo$ cat z
my $height = 5;
my $width = 5;
my @grid = [ Bool.pick xx $width ] xx $height;
my @neigh = [ ] xx $height;
for ^$height X ^$width -> $i, $j {
@neigh[$i][$j] = gather { take @grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < $height and 0 <= $j + .[1] < $width
for [-1,-1],[+0,-1],[+1,-1],
[-1,+0],( ),[+1,+0],
[-1,+1],[+0,+1],[+1,+1];
}
}
say @neigh[1][1].perl;
say @neigh[2][2].perl;
say @neigh[3][3].perl;
pmichaud@kiwi:~/p6/rakudo$ ./perl6 z
(Bool::True, Bool::False, Bool::False, Bool::False, Bool::True, Bool::True, Bool::False, Bool::False).list.item
(Bool::True, Bool::True, Bool::True, Bool::False, Bool::True, Bool::True, Bool::False, Bool::True).list.item
(Bool::False, Bool::True, Bool::True, Bool::False, Bool::True, Bool::True, Bool::True, Bool::True).list.item
pmichaud@kiwi:~/p6/rakudo$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment