Skip to content

Instantly share code, notes, and snippets.

@atelic
Created May 13, 2015 05:04
Show Gist options
  • Save atelic/5286e2c1e6297d57af05 to your computer and use it in GitHub Desktop.
Save atelic/5286e2c1e6297d57af05 to your computer and use it in GitHub Desktop.
Shortest FizzBuzz in ruby I can come up with
1.upto(100){|n|puts n%15==0?"FizzBuzz":n%5==0?"Buzz":n%3==0?"Fizz":n}
@tenebrousedge
Copy link

The world record is:

1.upto(100){|n|puts'FizzBuzz
'[i=n**4%-15,i+13]||n}

But I prefer:

1.upto(100){|e|puts ["%sBuzz"%x=[:Fizz][e%3]][e%5]||x||e}

Both are pretty fun abuses of the language. You can shave three bytes off your answer by using n%i<1 instead of n%i==0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment