News for hackers. Stuff that matters.
Re:FizzBuzz Still Works by irahul on Thursday November 15, 2012 @11:18AM (#4789226)
edit: In order to avoid overwriting output, the solution should read... if !multiple_of_3(i) && !multiple_of_5(i) output << i

No. Though output << i.to_s will produce the same result, his code is correct. And yours isn't if you do output << i

1. If not a multiple of 3 or 5 or 15, output = i.

2. If a multiple of 3, output << fizz.

3. If a multiple of 5, output << buzz

4. If a multiple of 15, "fizzbuzz". Already covered in 2 and 3 owing to <<

Apparently people mess up fizzbuzz even when they know it:)

There are no comments on this comment yet.