Created
August 8, 2014 15:24
-
-
Save nilsding/8e9bbb84875c771e33a0 to your computer and use it in GitHub Desktop.
Schreibe ein Programm, das die Zahlen von 12 bis 144 ausgibt, wobei alle durch 3 teilbaren Zahlen durch „Fizz“, alle durch 5 teilbaren Zahlen durch „Buzz“ und alle sowohl durch 3 als auch durch 5 teilbaren Zahlen durch „FizzBuzz“ ersetzt werden.
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
#!/usr/bin/env ruby | |
def fizzbuzz number | |
if number % 3 == 0 and number % 5 == 0 | |
"FizzBuzz" | |
elsif number % 3 == 0 | |
"Fizz" | |
elsif number % 5 == 0 | |
"Buzz" | |
else | |
"#{number}" | |
end | |
end | |
(12..144).each do |number| | |
puts fizzbuzz number | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment