3 ms·
https://gist.github.com/zenry/76b42f464a6430dd8524 https://gist.github.com/zenry/76b42f464a6430dd8524
by beardo 12y ago
https://gist.github.com/zenry/76b42f464a6430dd8524 https://gist.github.com/zenry/76b42f464a6430dd8524
- aw3c2 12y agoI find my version much more readable. I am a hobbyist, is there anything better in beardo's version apart from being re-usable? Mine seems more like a direct transformation of the "verbal" logic into simple code. <?php for ($i=1;$i<=100;$i++) { if ( ($i%3===0) AND ($i%5===0) ) { echo "FizzBuzz\n"; } else if ($i%3===0) { echo "Fizz\n"; } else if ($i%5===0) { echo "Buzz\n"; } else { echo $i."\n"; } } ?>
- beardo 12y agoThree things, mine is PHP 5.6 (Generator), second, I'm only using both 'Fizz' and 'Buzz' once. Maybe you can try to rewrite your code to something similar that concatenates the two strings ;) Last, mine version does not rely on `echo`, it generates a list and uses an foreach to print it.
- zimpenfish 12y agoBut why are these good things in a clearly trivial toy problem? YAGNI, premature optimisation, etc.