r/ProgrammerHumor • • Jan 16 '14

[deleted by user]

[removed]

1.3k Upvotes

446 comments sorted by

View all comments

Show parent comment

1

u/iopq Jan 17 '14

If you have an input N to get fizzbuzz for the first N numbers, you should cache first 15 answers in a bitmask like (00, 00, 01, 00, 10, ..., 00, 11) and print buzz for the first bit, fizz for the last bit, the number otherwise

1

u/Ph0X Jan 17 '14

Is that necessary though? The normal algorithm is O(n), which is as good as you can ever hope to achieve.

1

u/sophacles Jan 17 '14

In real life, that constant tends to matter a lot. So do cache misses.