Skip to content

Instantly share code, notes, and snippets.

@yhara
Created December 3, 2012 09:09
Show Gist options
  • Save yhara/4193770 to your computer and use it in GitHub Desktop.
Save yhara/4193770 to your computer and use it in GitHub Desktop.
FizzBuzz using Enumerable#lazy.
fizzer = [nil, nil, "Fizz"].cycle
buzzer = [nil, nil, nil, nil, "Buzz"].cycle
puts (1..Float::INFINITY).lazy.zip(fizzer, buzzer)
.map{|i, fizz, buzz|
fizz || buzz ? "#{fizz}#{buzz}" : i
}
.first(20)
@yhara
Copy link
Author

yhara commented Dec 3, 2012

First version (821e78) causes SEGV with ruby 2.0.0dev (2012-12-03 trunk 38154) [x86_64-darwin12.2.1].

@yhara
Copy link
Author

yhara commented Dec 12, 2012

(update) that SEGV is fixed by nobu :) http://bugs.ruby-lang.org/issues/7507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment