Created
September 26, 2013 03:44
-
-
Save rayning0/6709646 to your computer and use it in GitHub Desktop.
Fizzbuzz
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
# Raymond Gan | |
def fizzbuzz(n) | |
return "FizzBuzz" if (n % 3 == 0) && (n % 5 == 0) | |
return "Fizz" if n % 3 == 0 | |
return "Buzz" if n % 5 == 0 | |
end | |
fizz, buzz, fizzbuzz = [], [], [] | |
(1..50).each do |n| | |
case fizzbuzz(n) | |
when "Fizz" | |
fizz << n | |
when "Buzz" | |
buzz << n | |
when "FizzBuzz" | |
fizzbuzz << n | |
end | |
end | |
puts "Fizz numbers (divisible by 3 only) = #{fizz}" | |
puts "Buzz numbers (divisible by 5 only) = #{buzz}" | |
puts "FizzBuzz numbers (divisible by 3 and 5) = #{fizzbuzz}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment