Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Gray Code

by jdporter (Paladin)
on Jul 12, 2016 at 20:39 UTC ( [id://1167647]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1167647]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-29 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found