Last active
September 12, 2019 18:53
-
-
Save YuukiToriyama/5c0ae6381532fd7b539d346dcc8bfd44 to your computer and use it in GitHub Desktop.
ruby -e '(1..100).map{|n| case n % 15; when 0 then "FizzBuzz"; when 5,10 then "Buzz"; when 3,6,9,12 then "Fizz"; else n; end}.display'
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
#!/usr/bin/ruby | |
# 15で割った余りに注目してFizzBuzz | |
class Integer | |
def fizzbuzz | |
case self % 15 | |
when 0 then "FizzBuzz" | |
when 5,10 then "Buzz" | |
when 3,6,9,12 then "Fizz" | |
else self | |
end | |
end | |
end | |
(1..100).map(&:fizzbuzz).each{|e| puts e} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
関係ないけどScalaで書くとこんなかんじ
セミコロンがなくてきれい✨foreach printlnって書き方もいいね💖