Created
January 19, 2014 07:15
-
-
Save jackhooper/8501555 to your computer and use it in GitHub Desktop.
FizzBuzz, extended to be more complicated. Now, if n is a multiple of 7, the program prints out "Bazz", unless it is also a multiple of 14, in which case it prints out "Bozzle". If n is a multiple of 10, it prints out n, no matter what. Inspired by a section of David Fayram's 'FizzBuzz, A Deep Naval to Gaze Into' (http://dave.fayr.am/posts/2012-…
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
# FizzBuzz extended to be more complicated, in order to | |
# demonstrate the extensibility of this approach | |
# Jack Hooper 2014 | |
def fizzbuzz(n) | |
return n if n.modulo(10).zero? | |
output = "" | |
output.concat("Fizz") if n.modulo(3).zero? | |
output.concat("Buzz") if n.modulo(5).zero? | |
output.concat("Bazz") if n.modulo(7).zero? unless n.modulo(14).zero? | |
output.concat("Bozzle") if n.modulo(14).zero? | |
return n if output.empty? | |
output | |
end | |
1.upto(100) { |i| puts fizzbuzz(i) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment