Skip to content

Instantly share code, notes, and snippets.

@Frost
Created May 26, 2015 07:40
Show Gist options
  • Save Frost/dd1579bca7312ea43ff3 to your computer and use it in GitHub Desktop.
Save Frost/dd1579bca7312ea43ff3 to your computer and use it in GitHub Desktop.
FizzBuzz in ruby without modulo or integer division
class Cycle
def initialize(array = [])
@array = array
end
def call
result = @array.first
@array = @array.rotate
result
end
end
def fizzbuzz
buzz = Cycle.new(["", "","","","buzz"])
fizz = Cycle.new(["", "", "fizz"])
1.upto(100) do |i|
word = fizz.call + buzz.call
word = i.to_s if word == ""
puts word
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment