Created
August 3, 2012 20:50
-
-
Save ungoldman/3251385 to your computer and use it in GitHub Desktop.
Quest for the Shortest FizzBuzz
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 (var i=1;i<=100;i++){ | |
var s = ''; | |
if (i % 3 === 0) s += 'Fizz'; | |
if (i % 5 === 0) s += 'Buzz'; | |
console.log(s ? s : i); | |
} |
I took a shot at it, got it to 69 chars by only using recursion and string concatenation.
f=n=>console.log(n?n+(n%3?"":"fizz")+(n%5?"":"buzz")+(f(n-1)??""):"")
I got it to 58 chars:
for(x=0;x++<100;)print((x%3?"":"Fizz")+(x%5?"":"Buzz")||x)
56 ;)
for(i=0;++i<101;alert(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
@SiddharthShyniben You gotta use console.log
for the challenge, however even with replacing alert
you still are the shortest I've seen at 62 characters!!! 🎉
for(i=0;++i<101;console.log(i%5?f||i:f+'Buzz'))f=i%3?'':'Fizz'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got it down to 73 characters, using recursion to iterate over the 1..100 range.