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)
In reply to Golf: Indici to all sectors of an xD space by jeroenes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |