Skip to content

Instantly share code, notes, and snippets.

@rosslebeau
Last active August 29, 2015 14:08
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/60ebbb60d8e288ec7192 to your computer and use it in GitHub Desktop.
Save rosslebeau/60ebbb60d8e288ec7192 to your computer and use it in GitHub Desktop.
FizzBuzz in Ruby without conditionals
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
@rosslebeau
Copy link
Author

A readable version, and a shortened, "fun" version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment