Created
November 15, 2013 02:17
-
-
Save Chryus/7478071 to your computer and use it in GitHub Desktop.
Ruby fizzbuzz with each + case statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1..100).each do |x| | |
m3 = x.modulo(3) == 0 | |
m5 = x.modulo(5) == 0 | |
puts case | |
when (m3 and m5) then 'FizzBuzz' | |
when m3 then 'Fizz' | |
when m5 then 'Buzz' | |
else x | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment