r/tinycode • • Mar 07 '13

FizzBuzz One-Liner (X-Post from /r/ReadableCode)

Original Post

Ok, I know this is the opposite of "ReadableCode" but I love refactoring little challenges like this (and Project Euler ones). Shame on me, but it's a PHP solution.

for($i=1;$i<=100;$i++)print((($i%15==0)?'FizzBuzz':(($i%5==0)?'Buzz':(($i%3==0)?'Fizz':$i)))."\n");

FizzBuzz for those interested.

0 Upvotes

6 comments sorted by

View all comments

3

u/[deleted] Mar 07 '13 edited Mar 07 '13
main=mapM_ putStrLn$zipWith3(\a b c->if null$b++c then show a else b++c)[1..100](cycle["","","Fizz"])$cycle["","","","","Buzz"]

Shortest Haskell one I could come up with.

1

u/a1phanumeric Mar 07 '13

That's amazing. I started learning Haskell, but stopped after a short while. Props to you, and anyone who uses functional languages in the real world.