in reply to getting my neighbours in an N-dimensional space
# 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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: getting my neighbours in an N-dimensional space
by dash2 (Hermit) on Jan 21, 2002 at 21:33 UTC | |
by tye (Sage) on Jan 21, 2002 at 22:00 UTC | |
by Masem (Monsignor) on Jan 22, 2002 at 21:47 UTC |