The challenge is to create a 2D-array that contains indici of all sectors in a multi-dimensional space. The indici are given as unitary vectors in that space.
Eg., in a flat plane (2D), there are four sectors, so we have 4 vectors:
that point each to a quadrant:-1 -1 -1 1 1 -1 1 1
This of course comes handy when you want mirror some image or curve.| (-1, 1) | ( 1, 1) | ------------------- | (-1,-1) | ( 1,-1) |
The constraints are: (i) strict compliant, (ii) return a reference to an 2D-array and (iii) only the code inside the sub is counted (believe the last is standard, isn't it?). Furthermore: the vectors must be unitary vectors in the inner dimension. The function takes as input a scalar holding the number of dimensions disired.
Here is a starting point at 79 chars:
sub iterate_dim{ [map[map$_*2-1,split"",$_],map{substr unpack("B*",chr$_-1),-$_[0]}1..2 +**$_[0]] } #and call it: my $AoA = iterate_dim( 2 );
Have fun,
Jeroen
"We are not alone"(FZ)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Golf: Indici to all sectors of an xD space
by tilly (Archbishop) on Oct 10, 2001 at 21:55 UTC | |
by MeowChow (Vicar) on Oct 10, 2001 at 23:33 UTC | |
by tilly (Archbishop) on Oct 10, 2001 at 23:54 UTC | |
|
Re: Golf: Indici to all sectors of an xD space
by trantor (Chaplain) on Oct 11, 2001 at 02:47 UTC | |
by tilly (Archbishop) on Oct 11, 2001 at 03:06 UTC | |
by blakem (Monsignor) on Oct 11, 2001 at 03:12 UTC |