Skip to content

Instantly share code, notes, and snippets.

@stevenproctor
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenproctor/ecfb90fd6ceaa9880625 to your computer and use it in GitHub Desktop.
Save stevenproctor/ecfb90fd6ceaa9880625 to your computer and use it in GitHub Desktop.
def do_fizzbuzz(n)
fizz = ['', '', 'fizz'].cycle.lazy
buzz = ['', '', '', '', 'buzz'].cycle.lazy
fizzbuzz = fizz.zip buzz
puts (1..n).
zip(fizzbuzz.map(&:join)).
map {|number, translation| if translation.empty? then number else translation end}.
join("\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment