CUFP
jdporter
<p>
I needed a quick Gray code (specifically, a [http://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_Gray_code|binary reflected Gray code]), so I whipped this up. The one CPAN module which seems to implement Gray code, [dist://Math-PlanePath] is <i>wayy</i> too heavy for my needs.
</p>
<code>
# returns a list of vectors of numbers in (0,1)
sub gray2;
sub gray2
{
my($i) = @_;
$i <= 1 and return([0],[1]);
my @a = gray2($i-1);
( ( map { [ 0, @$_ ] } @a ), map { [ 1, @$_ ] } reverse @a )
}
my @a = gray2(3);
print "@$_\n" for @a;
</code>
<div class="pmsig"><div class="pmsig-170442">
I reckon we are the only monastery ever to have a dungeon stuffed with 16[523120|,]000 zombies.
</div></div>