Skip to content

Instantly share code, notes, and snippets.

@mje113
Created January 3, 2014 21:22
Show Gist options
  • Save mje113/8246844 to your computer and use it in GitHub Desktop.
Save mje113/8246844 to your computer and use it in GitHub Desktop.
# A
100.times do |i|
case [i % 3 == 0, i % 5 == 0]
when [true, true] then puts 'Fizz Buzz'
when [true, false] then puts 'Fizz'
when [false, true] then puts 'Buzz'
else
puts i
end
end
# B
FIZZBUZZ = {
[true, true] => 'Fizz Buzz',
[true, false] => 'Fizz',
[false, true] => 'Buzz'
}
100.times do |i|
puts FIZZBUZZ[ [i % 3 == 0, i % 5 == 0] ] || i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment