Skip to content

Instantly share code, notes, and snippets.

@audunolsen
Last active August 10, 2018 21:16
Show Gist options
  • Save audunolsen/b51807c0480dcdaeb1f87d6225fd6c33 to your computer and use it in GitHub Desktop.
Save audunolsen/b51807c0480dcdaeb1f87d6225fd6c33 to your computer and use it in GitHub Desktop.
My blind attempt at a compact script for the FizzBuzz game.
for(i=1;i<101;i++)
o =i%3?'':'Fizz',
o+=i%5?'':'Buzz',
console.log(o||i)
@audunolsen
Copy link
Author

audunolsen commented Aug 10, 2018

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 increment i 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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment