LoginSignup
8
2

More than 5 years have passed since last update.

怠惰なFizzBuzzが面白かったので自分も怠惰なFizzBuzz書いてみた

Last updated at Posted at 2017-11-18

怠惰なFizzBuzzが面白かったので パクリました 真似して書いてみました。
https://qiita.com/QUANON/items/c77c22b910651b54fe24

numbers = 1.step
fizzes = [nil, nil, "Fizz"].cycle
buzzes = [nil, nil, nil, nil, "Buzz"].cycle

numbers
  .lazy
  .zip(fizzes, buzzes)
  .map { |n, *yells| yells.any? ? yells.join : n }
  .take(30)
  .each(&method(:puts))
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
8
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2