Last active
August 29, 2015 14:08
-
-
Save rosslebeau/60ebbb60d8e288ec7192 to your computer and use it in GitHub Desktop.
FizzBuzz in Ruby without conditionals
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 fizzbuzz limit | |
i = 1 | |
answers = [['fizzbuzz', 'buzz'], ['fizz', i]] | |
loop do | |
puts answers[(i % 5) >> (Math.log2((i % 5) + 1).ceil - 1)][(i % 3) >> (Math.log2((i % 3) + 1).ceil - 1)] | |
i += 1 | |
1/((limit + 1) - i) | |
answers[1][1] = i | |
end | |
end | |
def fizzbuzzWat limit | |
answers = [['fizzbuzz', 'buzz'], ['fizz', 1]] | |
loop do | |
puts (answers[(answers[1][1] % 5) >> (Math.log2((answers[1][1] % 5) + 1).ceil - 1)][(answers[1][1] % 3) >> (Math.log2((answers[1][1] % 3) + 1).ceil - 1)] * ((answers[1][1] += ((limit + 1) - answers[1][1])/((limit + 1) - answers[1][1])) / answers[1][1])) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A readable version, and a shortened, "fun" version