Skip to content

Instantly share code, notes, and snippets.

@gavinheavyside
Forked from mrb/fizzbuzz.rb
Last active September 27, 2019 08:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavinheavyside/3879345 to your computer and use it in GitHub Desktop.
Save gavinheavyside/3879345 to your computer and use it in GitHub Desktop.
Writing FizzBuzz without modulus division or 'if'
fizz = [nil, nil, "Fizz"].cycle
buzz = [nil, nil, nil, nil, "Buzz"].cycle
(1..100).zip(fizz, buzz) do |num, *fb|
puts fb.compact.reduce(:+) || num
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment