Earlier quoted context omitted.
for i in range(1,101): print "FizzBuzz" if i % 15 == 0 else "Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else str(i) derp, works better of course Though I can't find out the score the page to test the code seems to be inaccessible if you are signed in. It just redirects you to the signed in page and the signout link is broken. Still it's a fun and cool idea
Redirects issue fixed. Can you try it now?
Fizz Buzz codegolf challenge in 15 languages
71–80 of 100 posts
Re: Fizz Buzz codegolf challenge in 15 languages
#72Earlier quoted context omitted.
for i in range(1,101): print "FizzBuzz" if not i % 15 else "Fizz" if not i % 3 else "Buzz" if not i % 5 else str(i) Even a little shorter :)
And a bit shorter still :D. Down to 102 chars now. for i in range(1,101):print "Fizz" if not i%3 else '' + "Buzz" if not i%5 else str(i) if (i%3) else '' Edit: Down to 82 characters now. I'm not sure if this would work on every Python, but it works on mine. for i in range(1,101):print(("Fizz"if i%3==0 else'')+("Buzz"if i%5==0 else''))or i
Re: Fizz Buzz codegolf challenge in 15 languages
#73Earlier quoted context omitted.
I came up with for(i=0;i earlier. 64 characters, because I don't have "var ", an extra set of parens, and a semicolon. Worse syntax, but hey, it's code golf.
I knew I could also drop the "var ", but I like to operate within the 140bytes challenge rules that say you're not allowed to leak into the global scope. I'll give you the 3 chars from the parens and semicolon, though - I got caught up with the idea of "hey, you can do this whole thing inside the for statement itself!" back when I did this!
Re: Fizz Buzz codegolf challenge in 15 languages
#74Earlier quoted context omitted.
for i in range(1,101): print "FizzBuzz" if not i % 15 else "Fizz" if not i % 3 else "Buzz" if not i % 5 else str(i) Even a little shorter :)
And a bit shorter still :D. Down to 102 chars now. for i in range(1,101):print "Fizz" if not i%3 else '' + "Buzz" if not i%5 else str(i) if (i%3) else '' Edit: Down to 82 characters now. I'm not sure if this would work on every Python, but it works on mine. for i in range(1,101):print(("Fizz"if i%3==0 else'')+("Buzz"if i%5==0 else''))or i
for i in range(1,101):print("Fizz"if i%3==0 else'')+("Buzz"if i%5==0 else'')or iRe: Fizz Buzz codegolf challenge in 15 languages
#75Earlier quoted context omitted.
https://www.hackerrank.com/fizzbuzz/level redirects to https://www.hackerrank.com/fizzbuzz
Fixed. Can you try it now?
I can however compile and verify my solution.
Re: Fizz Buzz codegolf challenge in 15 languages
#76My best C solution (scores a 96): #define d printf( main(i){i<101?(!(i%3)?d"Fizz"):0)|(!(i%5)?d"Buzz"):0)?d"\n"):d"%d\n",i),main(i+1):0;}
#define P printf(
main(n){(n%3?0:P"Fizz"))+(n%5?0:P"Buzz"))?:P"%d",n);P"\n");n>99?:main(n+1);}Re: Fizz Buzz codegolf challenge in 15 languages
#77My best C solution (scores a 96): #define d printf( main(i){i<101?(!(i%3)?d"Fizz"):0)|(!(i%5)?d"Buzz"):0)?d"\n"):d"%d\n",i),main(i+1):0;}
#define d printf(
main(i){iRe: Fizz Buzz codegolf challenge in 15 languages
#78Login seems borked, but here's my Perl at 59 chars (141 points): print(($_%3?"":"Fizz").($_%5?"":"Buzz")||$_,"\n")for 1..100
print(($_%3?"":"Fizz").($_%5?"":"Buzz")or$_,"\n")for 1..100
sadly, though it says they're running perl 5.14, it wouldn't work with 'say' which would have shaved off 7 characters.edit: Guess what? The code above does not work. It's what I typed into my buffer, and then fixed it on the console to use || instead of or. Oh operator precedence!
Re: Fizz Buzz codegolf challenge in 15 languages
#79Re: Fizz Buzz codegolf challenge in 15 languages
#80for(1..100){$_%15==0?print"FizzBuzz":$_%5==0?print"Buzz":$_%3==0?print"Fizz":print} Is my best perl golf so far... wrote this one eons ago. The site doesn't seem to work well however and it won't let me submit it. Would obviously be shorter with "say" instead of "print."
This is the expected output ( http://cdn.hackerrank.com/fizzbuzz.txt )