Created
June 17, 2022 10:56
-
-
Save taea/a43fe78807de446c3c820343a2365f6c to your computer and use it in GitHub Desktop.
恥ずかしくて提出されなかった fizzbuzz 珍回答の供養(その2)
This file contains hidden or 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 = {fizz: 3, buzz: 5} | |
# 除算の結果が1増えるタイミングでFizzBuzz言う | |
def timing(x, y) | |
x / y - (x - 1) / y == 1 | |
end | |
# FizzBuzz言うぞ! | |
def call(x) | |
@fizzbuzz.each do |key, value| | |
print key.capitalize if timing(x, value) | |
end | |
end | |
# FizzBuzz 言ってもいいかどうか判定 | |
def checker(x) | |
@fizzbuzz.each_value do |v| | |
return true if timing(x, v) | |
end | |
end | |
(1..20).each do |x| | |
checker(x) == true ? call(x) : print(x) | |
print "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment