3 ms·
The main reason I wrote this was after seeing a comment on HN about unusual FizzBuzz solutions. The f[0-4] and t[0-2] functions emulate the state of a determin
by gamegoblin 13y ago
The main reason I wrote this was after seeing a comment on HN about unusual FizzBuzz solutions.
The f[0-4] and t[0-2] functions emulate the state of a deterministic finite automata which determine divisibility of binary strings. The bits represent the binary strings. The left shift operator is used to "eat" bits.
See these two DFAs for an explanation:
http://stackoverflow.com/questions/15330027/regular-expression-for-binary-numbers-divisible-by-3 http://stackoverflow.com/questions/15330027/regular-expressi...
http://ugccomputerscience.blogspot.com/2012/02/dfa-of-binary-number-divisible-by-5.html http://ugccomputerscience.blogspot.com/2012/02/dfa-of-binary...
EDIT:
For those showing ways to do it with just addition and the like, I originally titled this "FizzBuzz using only bit twiddling" but a mod appears to have changed it...