3 ms·
> Fizzbuzz is one of those problems where there's really no clever hidden golfy solution better than the plain old first-reaction naive approach: an iteration w
by wott 10y ago
> Fizzbuzz is one of those problems where there's really no clever hidden golfy solution better than the plain old first-reaction naive approach: an iteration with if/elsif/elsif/else.
There are. With a funky calculation.
For example, taken from Rosetta C version:
for (int i=0;++i<101;puts("")) {
char f[] = "FizzBuzz%d";
f[8-i%5&12]=0;
printf (f+(-i%3&4+f[8]/8), i);
}
You might say the calculations are hidden if/else, but well...
- jgh 10y agoIt's possible to do with a switch statement as well (in C). Edit: Would be nice if the original author of that code snippet threw in some parentheses for a little clarity with the operator precedence.