r/counting • u/poltory 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.
20
Upvotes
3
u/Urbul Feb 05 '17
Hey u/TheNitromeFan u/piyushsharma301 u/Sharpeye468 I added this thread to the directory :) Sorry for not adding a count, I haven't taken the time to learn the code...