Last active
August 29, 2015 14:08
-
-
Save rosslebeau/72c571ed7b67f562a7d0 to your computer and use it in GitHub Desktop.
FizzBuzz in Ruby without conditionals or modulo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzzNoMod limit | |
i = 1.0 | |
answers = [['fizzbuzzxx', 'buzzxx'], ['fizzxx', i]] | |
loop do | |
puts answers[(i / 5.0).ceil - (i / 5.0).floor][(i / 3.0).ceil - (i / 3.0).floor].to_s.chop.chop | |
i += 1.0 | |
1/((limit + 1.0) - i).to_i | |
answers[1][1] = i | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment