Earlier quoted context omitted.
Because it's huge and this is a code golf challenge?
=\ No point in trying with Java then?
Fizz Buzz codegolf challenge in 15 languages
61–70 of 100 posts
Re: Fizz Buzz codegolf challenge in 15 languages
#621.upto(100).each {|x|s="#{'Fizz' if x%3 == 0}#{'Buzz' if x%5 == 0}";s=="" ? p(x): p(s)}
Re: Fizz Buzz codegolf challenge in 15 languages
#63Earlier quoted context omitted.
Some 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
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 :)
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 iRe: Fizz Buzz codegolf challenge in 15 languages
#6471 characters (129 points) with JavaScript. I actually wrote this quite a while back (and have also posted it on HN before) - code golf is pretty fun every now and then! for(var i=0;i++ For anyone else interested in doing code golf with JavaScript, here's a goldmine of byte-saving techniques: https://github.com/jed/140bytes/wiki/Byte-saving-techniques
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.Re: Fizz Buzz codegolf challenge in 15 languages
#65Re: Fizz Buzz codegolf challenge in 15 languages
#66for 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 :)
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
Re: Fizz Buzz codegolf challenge in 15 languages
#67print((Fizz)[$_%3].(Buzz)[$_%5]||$_,"\n")for 1..100
Re: Fizz Buzz codegolf challenge in 15 languages
#68for 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 :)
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=00Db30FFEDIT: ugh, sometimes I hate markdown, moved post to pastebin.
Re: Fizz Buzz codegolf challenge in 15 languages
#6971 characters (129 points) with JavaScript. I actually wrote this quite a while back (and have also posted it on HN before) - code golf is pretty fun every now and then! for(var i=0;i++ For anyone else interested in doing code golf with JavaScript, here's a goldmine of byte-saving techniques: https://github.com/jed/140bytes/wiki/Byte-saving-techniques
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.
Re: Fizz Buzz codegolf challenge in 15 languages
#70 package main
import(o"fmt")
func main(){s:=o.Print
for i:=1;i
Compiles and runs fine but obviously not go fmt compliant. I feel bad for even attempting it.Seems like the score should vary by language, Go (thankfully) makes it hard to be too terse. And of course in Java you're doomed prior to writing a single line of real logic code