Created
June 2, 2012 13:30
-
-
Save yuryofujita/2858445 to your computer and use it in GitHub Desktop.
Fizz Buzz問題
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
for i in 1..100 | |
fizz = i % 3 | |
buzz = i % 5 | |
if fizz == 0 and buzz == 0 then | |
puts "fizzbuzz" | |
elsif fizz == 0 then | |
puts "fizz" | |
elsif buzz == 0 then | |
puts "buzz" | |
else | |
puts i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
カウンターを設定、0とする。
カウンターに1を加える。
カウンターが100(の他、設定した値)を超えたなら、終了する。
カウンターが3と5の公倍数であるならば、「FizzBuzz」を出力し、2に戻る。
カウンターが3の倍数であるならば、「Fizz」を出力し、2に戻る。
カウンターが5の倍数であるならば、「Buzz」を出力し、2に戻る。
カウンターの数字を出力し、2に戻る。