http://qs1969.pair.com?node_id=1167647

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.

Replies are listed 'Best First'.
Re: Gray Code
by LanX (Saint) on Jul 12, 2016 at 22:37 UTC
Re: Gray Code
by Old_Gray_Bear (Bishop) on Jul 13, 2016 at 16:58 UTC
    Fade to Black

    ----
    I Go Back to Sleep, Now.

    OGB