The most widely used version of the Gray code is a bijection ω of the binary representation of the contiguous set of integers [ [ 0 ; n ] ] such that the binary representations ω ( i ) and ω ( i + 1 ) only differ by one bit ∀ 0 ≤ i < n .
For example, with n = 7 , we can choose ω : { 0 0 0 , 0 0 1 , 0 1 0 , 0 1 1 , 1 0 0 , 1 0 1 , 1 1 0 , 1 1 1 } ↦ { 0 0 0 , 0 1 0 , 0 1 1 , 0 0 1 , 1 0 1 , 1 0 0 , 1 1 0 , 1 1 1 } . How many such bijections ω of [ [ 0 ; 1 5 ] ] are there?
Clarification : We don't need the bijections to be cyclic i.e. we can have bijections for which the binary representations ω ( 0 ) and ω ( 1 5 ) differ by more than one bit (as in the provided example above.)
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
From the wording of the question, it was not obvious what were the permissible starting values for the sequence. My method is is quite similar to Romain Bouchard's in concept and quite different in implementation. n = 4 ; flip = Table [ 2 i , { i , 0 , 3 } ] ; chain = list , Block [ { last , bit , test } , If [ Length [ list ] = 1 6 , Sow [ list ] ; Return [ ] ] ; last = Last [ list ] ; Do [ test = BitXor [ bit , last ] ; If [ ¬ MemberQ [ list , test ] , chain ( Append [ list , test ] ) ] ; , { bit , flip } ] ; ] ] ; result = Reap [ chain ( { 0 } ) ; ]
This returned a 5712 row 16 column matrix. When 5712 did not work, 16 times that worked.
Fun problem. For the example shown, though, shouldn't 010 be the first element? The hamming distance between 001 and 010 is 2.
Thanks. I fixed it.
Problem Loading...
Note Loading...
Set Loading...
We can imagine the binary representations of integer 0 through 1 5 ( 0 0 0 0 , 0 0 0 1 , ⋯ , 1 1 1 1 ) as the coordinates of a unit hypercube (of dimension 4 ).
That way, a Gray code is a Hamiltonian path on this hypercube. Here is a bit of code to compute the total number of paths on the hypercube :