Live data from Hacker News

Fizz Buzz codegolf challenge in 15 languages

hackerrank.com

81–90 of 100 posts

Re: Fizz Buzz codegolf challenge in 15 languages

#81
post #43

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

say (1..100).map({ $_ %% (3|5) ?? ("Fizz" if $_ %% 3) ~ ("Buzz" if $_ %% 5) !! $_ }).join("\n") is my quick stab at a Perl 6 version. About the same length if I take out the spaces (which I'd rather not!).

Perl 6 is so cool!

I like the bit

  $_ %% (3|5)
A pretty nifty way to condense multiple values into a single test.

I don't always perl, but when I do sometimes I like to golf because it's fun.

Re: Fizz Buzz codegolf challenge in 15 languages

#84
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.

Mine was almost identical, except with i++But is there really no way to end the ternary operators without parenthesis?

Re: Fizz Buzz codegolf challenge in 15 languages

#85

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

Couldn't resist:

  class Solution{public static void main(String[] a){for(int i=0;++i
143 characters, 57 score

Re: Fizz Buzz codegolf challenge in 15 languages

#86
post #85

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

Couldn't resist: class Solution{public static void main(String[] a){for(int i=0;++i 143 characters, 57 score

[deleted]

Re: Fizz Buzz codegolf challenge in 15 languages

#87
post #74

Earlier quoted context omitted.

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

74

    for i in range(1,101):print(''if i%3 else'Fizz')+(''if i%5 else'Buzz')or i

Re: Fizz Buzz codegolf challenge in 15 languages

#89
post #85

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

Couldn't resist: class Solution{public static void main(String[] a){for(int i=0;++i 143 characters, 57 score

Nice. Lack of the ternary operator is the big sticking point I have with really compact Go solutions.

OTOH, in real world code I'm glad to see it gone.

Also just noticed the () on my import aren't needed, first one would have to be a space anyway but second one can be removed to get the character count down by one and a bit more jiggering of the if/else logic can shave another character:

  package main
  import o"fmt"
  func main(){s:=o.Print
  for i:=1;i

Re: Fizz Buzz codegolf challenge in 15 languages

#90
post #74

Earlier quoted context omitted.

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

74 for i in range(1,101):print(''if i%3 else'Fizz')+(''if i%5 else'Buzz')or i

70 now, still same idea.

    for x in range(1,101):print['','Fizz'][x%3==0]+['','Buzz'][x%5==0]or x
Post reply on HN