5 ms·
for i in range(1,101): print "FizzBuzz" if i %3 == 0 and i % 5 == 0 else "Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else str(i) Scores 69 in python but the
by jaegerpicker 14y ago
for i in range(1,101): print "FizzBuzz" if i %3 == 0 and i % 5 == 0 else "Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else str(i)
Scores 69 in python but the login/signup is broken :)
- e-dard 14y ago117 is my best Python solution yet, but I'm struggling to get higher than that!
- jaegerpicker 14y agonvm it's just running realllllly slow...
- glomph 14y agoSome simple ways to cut down on characters: 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 i
- jaegerpicker 14y agofor 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 :)
- adambard 14y agoAnd 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
- jaegerpicker 14y agoNice, The 82 character one works for me also, on Mac OS X python 2.7.3
- c4p 14y agoYou can drop the extra () which brings it down to 80. for i in range(1,101):print("Fizz"if i%3==0 else'')+("Buzz"if i%5==0 else'')or i
- GregBuchholz 14y ago74 for i in range(1,101):print(''if i%3 else'Fizz')+(''if i%5 else'Buzz')or i
- y2bd 14y ago70 now, still same idea. for x in range(1,101):print['','Fizz'][x%3==0]+['','Buzz'][x%5==0]or x
- GregBuchholz 14y agoExcellent. Down to 68. for x in range(1,101):print['','Fizz'][x%3<1]+['','Buzz'][x%5<1]or x
- twiceaday 14y agoMy shortest Python solution is 59 characters. Two tricks, use while instead of range, and use string repetition instead of lists n=1 while n<101:print'Fizz'*(n%3<1)+'Buzz'*(n%5<1)or n;n+=1 And here is a wacky one in 96 chars w=range(101) w[::3]=['Fizz']*34 w[::5]=['Buzz']*21 w[::15]=['FizzBuzz']*7 for s in w[1:]:print s
- ajennings 14y agoYou can save one more character with an exec loop n=1;exec"print'Fizz'*(n%3<1)+'Buzz'*(n%5<1)or n;n+=1;"*100
- jaegerpicker 14y agofor 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
- neeleshs 14y agofor i in range(1,101):print i%15==0 and 'FizzBuzz' or i%3==0 and 'Fizz' or i%5==0 and 'Buzz' or i has a score of 102
- crodjer 14y agoRedirects issue fixed. Can you try it now?
- jaegerpicker 14y agoWorks to login having trouble submitting however now
- glomph 14y agoOK I cheated and used google and found (60 chars): for i in range(1,101):print'FizzBuzz'[i*i%3*4:8--i**4%5]or i Pastebin of my explanation: http://pastebin.com/raw.php?i=00Db30FF http://pastebin.com/raw.php?i=00Db30FF EDIT: ugh, sometimes I hate markdown, moved post to pastebin.
- GregBuchholz 14y agoAwesomely ingenious use of math above. 59 if newlines count as 1. i=1 while i<101:print'FizzBuzz'[i*i%3*4:8--i**4%5]or i;i+=1
- glomph 14y agoShould have been empty string f[4:4]