Live data from Hacker News

Fizz Buzz codegolf challenge in 15 languages

hackerrank.com

71–80 of 100 posts

Re: Fizz Buzz codegolf challenge in 15 languages

#71
post #66

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?

Works to login having trouble submitting however now

Re: Fizz Buzz codegolf challenge in 15 languages

#72

Earlier 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

Nice, The 82 character one works for me also, on Mac OS X python 2.7.3

Re: Fizz Buzz codegolf challenge in 15 languages

#73
post #69

Earlier 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!

[deleted]

Re: Fizz Buzz codegolf challenge in 15 languages

#74

Earlier 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

You 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

Re: Fizz Buzz codegolf challenge in 15 languages

#75
post #65

Earlier quoted context omitted.

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

Fixed. Can you try it now?

It works, but I can't submit. the POST to https://www.hackerrank.com/rest/contests/fizzbuzz/challenges... eventually times out after 10 minutes.

I can however compile and verify my solution.

Re: Fizz Buzz codegolf challenge in 15 languages

#76

My 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;}

I was working on the same lines, and managed to bump it up to a score of 106:

  #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

#78

Login seems borked, but here's my Perl at 59 chars (141 points): print(($_%3?"":"Fizz").($_%5?"":"Buzz")||$_,"\n")for 1..100

This is highly amusing to me because my solution was almost exactly identical (and the same number of keystrokes:

  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

#79
post #77

My 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;}

you can get rid of the !() if you reverse the ?: #define d printf( main(i){i

excellent, missed that. :)

Re: Fizz Buzz codegolf challenge in 15 languages

#80
post #41

for(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 )

[deleted]
Post reply on HN