Last active
August 10, 2018 21:16
-
-
Save audunolsen/b51807c0480dcdaeb1f87d6225fd6c33 to your computer and use it in GitHub Desktop.
My blind attempt at a compact script for the FizzBuzz game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(i=1;i<101;i++) | |
o =i%3?'':'Fizz', | |
o+=i%5?'':'Buzz', | |
console.log(o||i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update… I recently did some googling to see if I could find anything shorter, and yeah, there is. A Medium Article titled Breaking Down The Shortest Possible FizzBuzz Answer examines the following code:
for(i=0;i<100;)console.log((++i%3?'':'fizz')+(i%5?'':'buzz')||i)
This actually looks a lot like my blind attempt, but it does a couple of smart things;
Remove
i++
from the for-compound, and instead incrementi
before the first ternary-if, saving a single "i".The other (fairly obvious) improvement is just omitting the output variable and placing any potential output-logic as a console.log argument. The solution is 64 bytes.
At this point I'm beaten. The room for improvement is so tiny that revisions of my solution simply become a carbon copy of the above line.
Maybe I'll try to find a new radical approach, the fight continues…