# You might already have this type of function available. # If not, it's needed for the next part: sub same_coord { my ($aref, $bref) = @_; my @acoord = @$aref; my @bcoord = @$bref; return 0 if ( scalar @acoord != scalar @bcoord ); foreach my $i ( 0..$#accord ) { return 0 if ( $acoord[$i] != $bcoord[$i] ); } return 1; } sub get_neighbors { my @coord = @_; my @n = ( [] ); foreach my $i ( 0..$#coord ) { @n = map { @left = @$_; map { [ @left, $_ ] } ( $coord[$i]-1..$coord[$i]+1) } @n; } @n = grep { !same_coord( \@coord, $_ ) } @n; return @n; }
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
In reply to Re: getting my neighbours in an N-dimensional space
by Masem
in thread getting my neighbours in an N-dimensional space
by dash2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |