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")}}
reply