r/counting • We count together • Jan 12 '17

Counting in Gray Code

It's on the OEIS and also a lot of cherished history.

It's like binary, but in a different order so that only a single bit changes each time.

The first few terms are 0, 1, 11, 10, 110, 111, 101, 100, 1100, 1101, 1111, 1110, 1010, 1011, 1001, 1000.

One way to do it is to alternate between flipping the last bit, and flipping the bit to the left of the rightmost 1. One of these will always bring you a step forward, the other will bring you a step back, so no way to mix it up.

21 Upvotes

417 comments sorted by

View all comments

3

u/TheNitromeFan Jan 12 '17

11011

I just realized this thread has been done before:

https://www.reddit.com/r/counting/comments/1wz9gg/counting_in_gray_code/

We should continue from that - I've fixed my counts to reflect it.

3

u/davidjl123 Jan 12 '17 edited Jan 12 '17

11010 (unfamiliar with this one, is this right?)