Skip to content

Instantly share code, notes, and snippets.

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 rosslebeau/d7da66c56e88dc3de3ce0440c766375c to your computer and use it in GitHub Desktop.
Save rosslebeau/d7da66c56e88dc3de3ce0440c766375c to your computer and use it in GitHub Desktop.
def fizzbuzz start, limit
(start..limit).to_a.map { |n|
printFizzBuzzForInput n
}
end
def printFizzBuzzForInput n
print "#{'fizz' * f(n)}"
print "#{'buzz' * g(n)}"
print "#{n.to_s * h(n)}"
print "\n"
end
def f n
((n % 3 / (n % 3 + 1.0)).ceil - 1) * (-1)
end
def g n
((n % 5 / (n % 5 + 1.0)).ceil - 1) * (-1)
end
def h n
(n % 3 / (n % 3 + 1.0)).ceil * (n % 5 / (n % 5 + 1.0)).ceil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment