I hope you like this one, as it is my ever-first attempt at a golf.

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:

-1 -1 -1 1 1 -1 1 1
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.