Live data from Hacker News

Fizz Buzz codegolf challenge in 15 languages

hackerrank.com

61–70 of 100 posts

Re: Fizz Buzz codegolf challenge in 15 languages

#61

Earlier quoted context omitted.

Because it's huge and this is a code golf challenge?

=\ No point in trying with Java then?

You can do some decent golfing in Java. For improvement, how about removing all the casts, FP arithmetic, everything from Math, etc?

Re: Fizz Buzz codegolf challenge in 15 languages

#63
post #37

Earlier 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 :)

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

#64
post #56

71 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

#65

After 10 minutes, I was able to log in, but now I can't access the fizzbuzz page ):. Maybe I'll try later.

https://www.hackerrank.com/fizzbuzz/level redirects to https://www.hackerrank.com/fizzbuzz

Fixed. Can you try it now?

Re: Fizz Buzz codegolf challenge in 15 languages

#66

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 :)

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?

Re: Fizz Buzz codegolf challenge in 15 languages

#68

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 :)

OK 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

EDIT: ugh, sometimes I hate markdown, moved post to pastebin.

Re: Fizz Buzz codegolf challenge in 15 languages

#69
post #56

71 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.

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

#70
Go (golang) - 157 characters/43 score

  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

Post reply on HN