Created
March 23, 2012 17:48
-
-
Save TimToady/2173143 to your computer and use it in GitHub Desktop.
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
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