9 ms·
Fizz Buzz codegolf challenge in 15 languages
- cookrn 14y agoWhy does authorizing with github need permission to "Update my profile"?
- lmm 14y agoThe obvious scala implementation is 160 chars and works locally, but the site claims I score 0 for it: object Solution {def main(args: Array[String])=1 to 100 map {x=>System.out.print(if(x%3>0&&x%5>0)x else if(x%5>0)"Buzz" else if(x%3>0)"Fizz" else "FizzBuzz")}}
- idlecool 14y agoyou are missing out new line characters after each output. `System.out.println` should work.
- deleted 14y ago[deleted]
- patman_h 14y agoWhen I tried out the site, it gave me a score of 0 for submissions that compiled but produced the wrong output. I've never written scala before but it looks like your logic is wrong. Edit: I tweaked your code and got a score of 34 object Solution {def main(args: Array[String])=1 to 100 map {x=>System.out.println(if(x%3==0&&x%5==0)"FizzBuzz" else if(x%5==0)"Buzz" else if(x%3==0)"Fizz" else x)}}
- urbanautomaton 14y ago"You Scored: 56.00000000000001". :-)
- ricardobeat 14y agoHow do you get javascript to work? I tried `process.stdout.write`, `console.log`, but the score is always zero. Other issues: - The "Solve FizzBuzz" button doesn't go anywhere if you are logged in, neither does "The Scenario" up top. - Forum doesn't work (please fill in all the required fields - they already are) - Signout link doesn't work
- ddrmaxgt37 14y agoI'm wondering the same thing...
- idlecool 14y ago`console.log` works fine.
- ricardobeat 14y agoWhat is wrong with this then (not my entry): process.stdin.resume(); process.stdin.setEncoding("ascii"); process.stdin.on("data", function (input) { var output = '' if (input % 3 === 0){ output += 'Fizz' } if (input % 5 === 0){ output += 'Buzz' } console.log(output || input) }); Testing locally with for(i=1;i<=30;i++){ process.stdin.emit('data', i.toString()) } process.stdin.destroy() gives the correct results.
- dheerajrav 14y agoThere is no input. You have to print the desired result for all numbers between 1-100
- ricardobeat 14y agoReally? I just wasted 20 minutes trying to figure out whatever that boilerplate was supposed to receive :/
- dheerajrav 14y agoprocess.stdin.resume(); process.stdin.setEncoding('ascii'); process.stdin.on('data', function (input) { numbers = input.split("\n"); sum = parseInt(numbers[0]) + parseInt(numbers[1]) process.stdout.write(sum+"\n"); }); this is a sample code that takes a two digit integer and prints its sum. Can you use this format and see if it works?
- jaegerpicker 14y agofor 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
- keelzebub 14y agoIt seems like an neat idea! But I'm not I'm sure if I would make whitespace count as characters. Seem like that punishes good formatting. I also scored 56.00000000000001 :D (I tried the Perl one)
- 5h 14y agoseems to be dead ... wonder if they are running the code submitted on the webserver & people have submitted busy loops or somesuch
- idlecool 14y agoThere was a DDoS attack. Fixed.
- ddrmaxgt37 14y agohow do we print in js?
- dheerajrav 14y agoprocess.stdout.write();
- dheerajrav 14y agoHi, can you check now. It is working. We run it in our codecheckers and not on webservers.
- 5h 14y agoCool, much faster now :)
- hallowtech 14y agoI don't understand why this only gets a score of 1: static String[] c = { "", "FizzBuzz", "Buzz", "Fizz" }; public static void main(String[] args) { for(int i = 1; i <= 100; i++) { c[0] = ""+i; int f = ((int)Math.ceil((i%3)/3.0))+1; int b = ((int)Math.ceil((i%5)/5.0))*2; System.out.println(c[(f+b)%4]); } }
- ricardobeat 14y agoBecause it's huge and this is a code golf challenge?
- hallowtech 14y ago=\ No point in trying with Java then?
- Tuna-Fish 14y agoYou can do some decent golfing in Java. For improvement, how about removing all the casts, FP arithmetic, everything from Math, etc?
- mikle 14y agofizzbuzz and challenge in the same sentence? After the last guy I interviewed couldn't code Fibonacci or even explain how to do it, I think I lost my faith.
- ollysb 14y agoBit confused by the ruby version. The signature you're given is: #!/bin/ruby # Head ends here def fizzbuzz_solve n end # Tail starts here I presumed this meant you were supposed to return a value of n, fizz, buzz or fizzbuzz for the value of n. When I tried to compile I got a score of 0 though. What are you supposed to do with the value of n, solve fizzbuzz for 1..n ?
- hallowtech 14y agoIn other languages n is the number between 1-100 passed into the method. The loop is outside of fizzbuzz_solve.
- 4ngle 14y agoThe boilerplate (include the shebang) counts towards your score, so just ditch it and start anew.
- verdverm 14y ago89 char in c
- agentultra 14y agofor(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."
- rvivek 14y agoThis is the expected output (http://cdn.hackerrank.com/fizzbuzz.txt http://cdn.hackerrank.com/fizzbuzz.txt)
- deleted 14y ago[deleted]
- colomon 14y agosay (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!).
- agentultra 14y agoPerl 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.
- rmah 14y agoprint(($_%3?"":Fizz).($_%5?"":Buzz)||$_,"\n")for 1..100 No need to quote the strings in some cases :-)
- rvivek 14y agoJust added a sample output. I think some of the code snippets are missing the "\n"
- deleted 14y ago[deleted]
- GregBuchholz 14y agoLogin seems borked, but here's my Perl at 59 chars (141 points): print(($_%3?"":"Fizz").($_%5?"":"Buzz")||$_,"\n")for 1..100
- rvivek 14y agoWhat happens on login?
- GregBuchholz 14y agoI tried the github option, and the first time I tried, it barfed about "unauthorized credentials" or some such after the redirect back from github, bringing me to another hackerrank login page. I tried it again, and it choked right away with the same message. Third time and it asks to "Confirm Submission", but hung after hitting yes.
- colomon 14y agoNice! Much better than my first stab. Slightly shorter (56 chars) P6 version: say(("Fizz" if $_%%3)~("Buzz" if $_%%5)||$_) for 1..100
- hercynium 14y agoThis 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!
- nappy-doo 14y agoMy 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;}
- wickberg 14y agoI 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);}
- loumf 14y agoyou can get rid of the !() if you reverse the ?: #define d printf( main(i){i<101?(i%3?0:d"Fizz"))|(i%5?0:d"Buzz"))?d"\n"):d"%d\n",i),main(i+1):0;}
- nappy-doo 14y agoexcellent, missed that. :)
- ddrmaxgt37 14y agoAfter 10 minutes, I was able to log in, but now I can't access the fizzbuzz page ):. Maybe I'll try later.
- ddrmaxgt37 14y agohttps://www.hackerrank.com/fizzbuzz/level https://www.hackerrank.com/fizzbuzz/level redirects to https://www.hackerrank.com/fizzbuzz https://www.hackerrank.com/fizzbuzz
- crodjer 14y agoFixed. Can you try it now?
- ddrmaxgt37 14y agoIt works, but I can't submit. the POST to https://www.hackerrank.com/rest/contests/fizzbuzz/challenges/fizzbuzz/submissions https://www.hackerrank.com/rest/contests/fizzbuzz/challenges... eventually times out after 10 minutes. I can however compile and verify my solution.
- aidenn0 14y agoMy best malbolge version: bCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{]s9wvutsU2ponmlNjihgfedcba`_^W{[ZYXWVUTSRQPONMLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.n,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*j('&%$#z@~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.n,+*)('&%$#"!~}|{zyxwvutm32ponmlkjihgfedcb[!_X]VzZYXWVUTSRQ3ONMLKJIHGFEDCB;_?!=<;:981UT43210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&f$#"!x>|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-CgGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJCBfeEDCBA@9>=<5Y9876543s10/.-,+*)('&%$#"!~}|u;y[wvo5mrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJCBfFEDCBA@?>7<;4X876/432+O/.-,+*)('g%|B"!~}|u;yxwvutsrqponmlkjihgfedcba`_^]V[ZYXWVUTSRQPImMLKJCHG@d'CB;_?!=<;:981UT43210/.-,+*)('&%$#"!~}|{z\xwvutsl2Sonmf,jihgfedcba`_^@\[ZYXQutTSRQPO1lFKJIHGFEDCBA@?>=<;:92V6543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjiKgfedcba`Y}]\[ZYXWVUTSRQPO1lLKDIHGFEDCBA@?>=<;4X876543s10)M-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=};:9876543210/.-,+*)('&%$#"!~}|u;sxwvutsrqj0nmfkjiha'&dcb[!_^]V[ZYXWVUTSRQPONMLKJIBfFEDCBA@?>=};:9870T43210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=};:3W765432r0/.-,%I)(!&}CB"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$d"!~}|{zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDC<A@?>=<;:98765.RQ10/.-,+*)('&%$#z!~}|{zyxwvutsrqj0hmf,jiha`&dcba`_^]\UTxXWVUTSRQPONMLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}v{zyr8vutslqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=};:3W76543s1*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-m+*)('~D$#"!~}|{z\xwp6tsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDC<A@?>=<;:98765.R210/.n,+*)('&%$#"!~w={zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDC<A@?>=<;:98765.R210/.n,+*)('&%$#z@~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}v{zyr8vutslqj0/Plkd*hgfedFba`_^]\[ZYXWVUTSRKoONMLKJ,BfeEDCBA@?>=<;:3W76543210/.-m+*)('&%${Ay~}|{zyxwvo5srqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHA@dDCBA:?>=<;:92V654-210/.-,+*)('&%$#"!~}|{zyxwp6tsrqponmlkjihgfedcEa`_^]\[ZYXQuUTMRQPONMFjJ,BfeEDCBA@?>=<;:3W76543210/.-m+*)('&%${A!~wv<zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=};:3W76543s1*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9y76543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHA@dDCBA@?>=<;:9876543s10)M-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHA@dDCBA@?>=<;:9876543210/.n,+*)(!E%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$d"!~}|{zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-m+*)('&%$#"!~}|{zyr8vutsl2jonmlkjihgfedcb[!_X]VzZYXWV8TSRQPONMLKJIHGFED=aA@?>=6;:3WV6543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-m+*)('&%$#"!~}|{zyr8vutsrqpih.lkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-m+*)"FE%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/Plkd*hgfedFba`_^]\[ZYXWVUTSRKoONMLKJ,BfeEDCBA@?>=<;:3W76543210/.-m+*)('&%$#"!~}|{zyr8vutsrqponmlkjihafedcb[!_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-m+*)"F&f$#"!x>|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&}$#"!~}|{t:xqvutm32ponmlkjihgfedcb[!_^]\[TYXWVUTSRQPONMLKJIBfFEDCBA@?>=};:9870T43210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=};:3W765432r0/.-,%I)(!&}CB"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$d"!~}|{zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&f$#"!~}|{zyxwvutsrqpong-Njihgf_%cba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"b~w={zyxwvutsrqponPlkjihgf_%cba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('g%$#"!~}|{zyxq7utslqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~`|{zyxq7utsrqponmfkjihgfedcba`Y}]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)(h&%$#"!~}|{zs9wvutsrqponmfkjiha'&dcb[!_^]\UZYXWVUTSRQPONMLKJIBfFEDCBA@?>=<;:92V6543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFED&BA@?>=6Z:9876543210/.n,+*#G'&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/Plkd*hgfedFba`_^]\[ZYXWVUTSRKoONMLKJ,BfeEDCBA@?>=<;:3W76543s10/.-,+*)"F&%$#"!~}|uzyr8vutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDC%A@?>=6Z:9876543210/.-,+$H('&%$#"!~}|{zyxwvutsrqjonmlkjihgfedcb[!_X]VzZYXWV8TSRQPONMLKJIHGFED=aA@?>=6;:3WV6543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9y70T.3210/.-,+*)('&%${A!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA@?!=<;:9876543210/.-,%I)(!&}CB"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=};4X87654321*/.-&J*)('&%$#"!~`v<;yxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9y1U543s10)M-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcEa`Y}]\[ZSXWVUTSRQPONMLKDhHGFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.n,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDC%A@?>=<;:981U543210/.-,+$H('&%$#"!~}|{zyxwvutsrqjonmlkjihgfedcb[!_X]VzZYXWV8TSRQPONMLKJIHGFED=aA@?>=6;:3WV6543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9y1U5.3210/.'K+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543210/.-,+*)('&f$#"!x>|u;yxwvunsrqpi/glkjihgfedcba`_^]VzZYXWV8TSRQPONMLKJIHGFED=aA@?>=6;:3WV6543210/.n,+$H(h&%$#"!~}|{zs9Zvutm32ponmlkjihgfedcb[!_^W\[TxRQuUTSRQPO1lLKJIHGFEDCBA@?>=<;:9y1UT43210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVU7rRQPONMLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543s10)M'&J*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.n,+*)('&%$#"!~}|{zyxwvutm32ponmlkjihgfedcb[!_X]VzZYXWVUTSRQ3ONMLKJIHGFEDCB;_?!=<;:981UT43210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:987654t210/.-,+*)(!E}$#"!~}|{zyr8vutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-CgAFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvo5srqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutsrkj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-CgGFEDC%A@?>=6Z:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-CgfFEDCBA@?>=<;:9876543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-CgG@EDCBA@?>=<;:981U543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/Plkd*hgfedFba`_^]\[ZYXWVUTSRKoONMLKJ,BfeEDCBA@?>=<;:3W76543210/.n,+*#G!&%$#z@~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDC%A:^>=<;:9876543210/.-m+*)('~D$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFEDCBA@?>=<;:9876543210/.-,%I)('&%$#"!~}|^zyr8vutmrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHG@dDCBA@?>=<;:3876543210/.-,+*)('&%${A!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHAeEDCBA:?>=<;:987654321*N.-,l*)('&%$#"!~}|u;:xwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLKJIHGFEDCBA@?>=<;:9876543s10/.-,+*)('&%$#"!~}|u;y[wvo5mrqj0/mlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHGFED=aA:?>=<;:981U543210/.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lLK-IHG@dDCBA@?>7[;49876543210/.-,+$H('&%$#"!~`|u;sxwvutsrqj0nmfkjiha'&dcb[!_^]\[ZYXWVUTSRQPONMLK-IHAeEDCBA@?!=<;:92V6543,+ON.-,+*)('&%$#"!~}|{zyxwvutsrqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPO1lY
- adambard 14y agoI don't know why I'm such a sucker for this sort of thing. I couldn't get it to score me, but here's 104 chars of Clojure: (for [i(range 100):let[d #(= (mod i %) 0)]](println(cond(d 15)"FizzBuzz"(d 3)"Fizz"(d 5)"Buzz":else i)))
- Hupo 14y ago71 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++<100;console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||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 https://github.com/jed/140bytes/wiki/Byte-saving-techniques
- ricardobeat 14y agoGood, now everyone can just copy & paste it and the competition is a tie ;)
- xymostech 14y agoI came up with for(i=0;i<100;)console.log((++i%3?"":"Fizz")+(i%5?"":"Buzz")||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.
- Hupo 14y agoI 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 14y ago[deleted]
- tobr 14y agoMine was almost identical, except with i++<100 instead of ++i%3? etc. Also 64 characters. But is there really no way to end the ternary operators without parenthesis?
- caioariede 14y agoErlang version (more verbose): lists:map(fun(N)->io:fwrite("~s~n",[if N rem 15==0->"FizzBuzz";N rem 3==0->"Fizz";N rem 5==0->"Buzz";true->integer_to_list(N)end])end,lists:seq(1,100)).
- pg_bot 14y agoCouldn't get it to run but here is my best in ruby: 1.upto(100).each {|x|s="#{'Fizz' if x%3 == 0}#{'Buzz' if x%5 == 0}";s=="" ? p(x): p(s)}
- oo 14y ago# Perl at 51 characters (149 points). print((Fizz)[$_%3].(Buzz)[$_%5]||$_,"\n")for 1..100
- georgemcbay 14y agoGo (golang) - 157 characters/43 score package main import(o"fmt") func main(){s:=o.Print for i:=1;i<101;i++{f,b:=i%3==0,i%5==0 if!(f||b){s(i)}else{if f{s("Fizz")} if b{s("Buzz")}} s("\n")}} 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
- tehzord 14y agoCouldn't resist: class Solution{public static void main(String[] a){for(int i=0;++i<101;)System.out.println(i%15==0?"FizzBuzz":i%3==0?"Fizz":i%5==0?"Buzz":i);}} 143 characters, 57 score
- deleted 14y ago[deleted]
- georgemcbay 14y agoNice. 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<101;i++{if f,b:=i%3==0,i%5==0;(f||b){if f{s("Fizz")} if b{s("Buzz")}}else{s(i)} s("\n")}}
- trebor 14y agoLooks like I can't submit my code. I can run it, but not submit it.
- Ozark 14y agomy best c++ solution scores 75 points with 126 characters #include<iostream> main(){for(int i=0;i++<100;){if(i%5&&i%3)std::cout<<i;std::cout<<(i%3?"":"Fizz")<<(i%5?"":"Buzz")<<'\n';}}
- agentultra 14y agoSee also, http://codegolf.com http://codegolf.com
- 1331 14y agoHaskell - 112 bytes / 88 score a="Fizz" b="Buzz" i%j=mod i j==0 f i |i%15=a++b |i%5=b |i%3=a |True=show i main=mapM_ (putStrLn.f) [1..100]