0.あると望ましい(どうでもいい)前提知識
超久しぶりの投稿!
気分転換のためにfizzbuzzを作成してみました。
インドミナスレックス(IndominusRex):ヴェロキラプトルとティラノザウルスを融合させた恐竜。
インドラプトル(Indoraptor):インドミナスレックスとヴェロキラプトルを融合させた恐竜。
この知識を前提に変形fizzbuzzを作ってみた。
最後にインドラプトルが表示されていれば成功!
1.コード
method_fizzbuzz.rb
def act_dino(dinosor)
if dinosor == 'Tyrannosaurus'
puts 'Bite!!'
elsif dinosor == 'Stegosaurus'
puts 'Waving the tail!'
else
puts '???'
end
end
def FizzBuzz_dinosor(n)
#インドラプトル
if n % 45 == 0
'Indoraptor'
#インドミナスレックス
elsif n % 15 == 0
'IndominusRex'
#ティラノサウルス
elsif n % 5 == 0
'Tyrannosaurus'
#ヴェロキラプトル
elsif n % 3 == 0
'Velociraptor'
else
n.to_s
end
end
act_dino("tiger")
act_dino("Stegosaurus")
n=0
while n < 45 do
n += 1
puts FizzBuzz_dinosor(n)
end
2.実行結果
c:\ruby_pg>ruby method_fizzbuzz.rb
???
Waving the tail!
1
2
Velociraptor
4
Tyrannosaurus
Velociraptor
7
8
Velociraptor
Tyrannosaurus
11
Velociraptor
13
14
IndominusRex
16
17
Velociraptor
19
Tyrannosaurus
Velociraptor
22
23
Velociraptor
Tyrannosaurus
26
Velociraptor
28
29
IndominusRex
31
32
Velociraptor
34
Tyrannosaurus
Velociraptor
37
38
Velociraptor
Tyrannosaurus
41
Velociraptor
43
44
Indoraptor
c:\ruby_pg>