3 ms·
It's like FizzBuzz - do you handle the 3 first or the 5?
by stephengillie 9y ago
It's like FizzBuzz - do you handle the 3 first or the 5?
- reificator 9y agoYou handle the 15 first to avoid the accumulator requirement.
- stephengillie 9y agoMy 15 falls through both the 3 and the 5 paths. So I must do 3 first, or 15 will be BuzzFizz.
- jackweirdy 9y agoI think the point was that you do If n%15==0 First, then the others. But it’s a pedantic point anyway (like this one)
- sk0g 9y agoOr you can print fizz and buzz in independent statements, or it against printing the raw number, and then print a new line for each number in the end.
- reificator 9y agoNo, I'm saying just do a switch with four branches, %15, %5, %3, default, and break all of them. That way you're explicit about the ambiguous case and you avoid string concat or stateful stdout logic.