Enumerator
を使ったシンプルな FizzBuzz です。
fizzer = [nil, nil, 'Fizz'].cycle
buzzer = [nil, nil, nil, nil, 'Buzz'].cycle
1.upto(100) { |i|
fizz, buzz = fizzer.next, buzzer.next
puts fizz || buzz ? "#{fizz}#{buzz}" : i
}
Array#cycle
がクールですね♥
Go to list of users who liked
More than 5 years have passed since last update.
Enumerator
を使ったシンプルな FizzBuzz です。
fizzer = [nil, nil, 'Fizz'].cycle
buzzer = [nil, nil, nil, nil, 'Buzz'].cycle
1.upto(100) { |i|
fizz, buzz = fizzer.next, buzzer.next
puts fizz || buzz ? "#{fizz}#{buzz}" : i
}
Array#cycle
がクールですね♥
Register as a new user and use Qiita more conveniently
Go to list of users who liked