Hacker News new | past | comments | ask | show | jobs | submit login

It's just modular math. The output is fizz if the output is orthogonal to 0 mod 3, and buzz if it is orthogonal to 0 mod 5. It's fizzbuzz when it's 0 mod 15.

Now, since 15 is divisible by 3, it's easy to see that x = 0 mod 3 iff x = {0, 3, 6, 12} mod 15, and similarly x = 0 mod 5 iff x = {0, 5, 10} mod 15. So you can see now that you can determine the output for a given index based on the remainder after dividing by 15, so the sequence must repeat every 15 elements.




> Shipper: Hmmm. I don't think that list is valid... > Google: Good. So your program will have to detect that.

Your program might receive bad input, and it's your responsibility to output an error code if so.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: