Skip to content

Instantly share code, notes, and snippets.

@TimToady
Created March 23, 2012 17:48
Show Gist options
  • Save TimToady/2173143 to your computer and use it in GitHub Desktop.
Save TimToady/2173143 to your computer and use it in GitHub Desktop.
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment