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
It 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)
I 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]);
}
}
fizzbuzz 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.
Bit 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 ?
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."
I 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.
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!
I'd never heard of malbolge until last night, when it played a role in the mystery on CBS' "Elementary" (an excellent series, BTW). Kind of weird to encounter such an obscure language twice in under 24 hours.
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!
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!
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)).
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
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<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")}}
99 comments
[ 3.2 ms ] story [ 172 ms ] threadI've never written scala before but it looks like your logic is wrong.
Edit: I tweaked your code and got a score of 34
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
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?
Scores 69 in python but the login/signup is broken :)
Even a little shorter :)
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
EDIT: ugh, sometimes I hate markdown, moved post to pastebin.
Update : Logged in, Takes forever to submit
can you check now. It is working. We run it in our codecheckers and not on webservers.
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."
I like the bit
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.
No need to quote the strings in some cases :-)
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!
#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 can however compile and verify my solution.
https://github.com/jed/140bytes/wiki/Byte-saving-techniques
But is there really no way to end the ternary operators without parenthesis?
1.upto(100).each {|x|s="#{'Fizz' if x%3 == 0}#{'Buzz' if x%5 == 0}";s=="" ? p(x): p(s)}
print((Fizz)[$_%3].(Buzz)[$_%5]||$_,"\n")for 1..100
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
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: