I needed a quick Gray code (specifically, a binary reflected Gray code), so I whipped this up. The one CPAN module which seems to implement Gray code, Math-PlanePath is wayy too heavy for my needs.
# 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;
I reckon we are the only monastery ever to have a dungeon stuffed with 16
,000 zombies.