News for hackers. Stuff that matters.
Re:What's the shortest FizzBuzz you can write? What language? by rorrr on Saturday September 10, 2011 @04:32AM (#2981166)
the shortest I could do is 72 characters in PHP. I have no idea how they can do 56.

    <? while(++$i<101)echo $i%15?$i%5?$i%3?$i:'Fizz':'Buzz':'FizzBuzz',"\n";
Re:What's the shortest FizzBuzz you can write? What language? by jontsai on Saturday September 10, 2011 @03:38PM (#2982291)
Don't think you can do $i%15, still need to do that check separately. I like how you can leave out the closing ?>. you can also save 2 spaces by getting rid of whitespace between statements and symbols .

The comments on the RapLeaf blog post I linked to in this thread has a guy trying out different Ruby solutions. Very clever!

Re:What's the shortest FizzBuzz you can write? What language? by rorrr on Saturday September 10, 2011 @06:55PM (#2982714)
That code produces correct output. It passed.

PHP does not require a closing ?>

Re:What's the shortest FizzBuzz you can write? What language? by jontsai on Saturday September 10, 2011 @07:36PM (#2982798)
Ohhh. I was thinking about it wrong. Probably obvious to others, but I forgot about the property that if you have primes p and q, any number n (evenly) divisible by p that is also divisible by q must be divisible by the product of p*q.

That shortcut is a result of hyper-optimization and I was thinking more along the lines of code-reusability (e.g. if the rules of FizzBuzz were changed from %3 and %5 to %x and %y) =P

Re:What's the shortest FizzBuzz you can write? What language? by par on Saturday September 10, 2011 @11:07AM (#2981676)
I only worked on it for a few minutes and got 114 chars in Python

  for i in range(1,101):
   if i%15==0:print'FizzBuzz'
   elif i%3==0:print'Fizz'
   elif i%5==0:print'Buzz'
   else:print i
Now I am on the hunt to figure out how to do it in 56, there goes my afternoon.
Re:What's the shortest FizzBuzz you can write? What language? by jontsai on Saturday September 10, 2011 @03:35PM (#2982285)
Heh, shortest I could do in Python after several hours was 62

  for x in range(1,101):print'Fizz'*(x%3==0)+'Buzz'*(x%5==0)or x
Off by 6 bytes!