Skip to content

Instantly share code, notes, and snippets.

View rosslebeau's full-sized avatar

Ross LeBeau rosslebeau

View GitHub Profile
lonelyInteger :: [Int] -> Int
lonelyInteger = head . head . dropWhile ((>1) . length) . group . sort
@rosslebeau
rosslebeau / gist:d4de0c7044ee5f93581a
Last active May 23, 2016 21:49
FizzBuzz in Ruby without conditionals using logarithms - one liner
def fizzbuzz limit, start
loop do
puts "#{'fizz' * (~(((start % 3) >> (Math.log2((start % 3) + 1).ceil - 1)) * 2))[1]}#{'buzz' * (~(((start % 5) >> (Math.log2((start % 5) + 1).ceil - 1)) * 2))[1]}#{start.to_s * ((start % 3) >> (Math.log2((start % 3) + 1).ceil - 1)) * ((start % 5) >> (Math.log2((((start += ((limit + 1) - start)/((limit + 1) - start)) - 1) % 5) + 1).ceil - 1))}"
end
end
@rosslebeau
rosslebeau / gist:72c571ed7b67f562a7d0
Last active August 29, 2015 14:08
FizzBuzz in Ruby without conditionals or modulo
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
@rosslebeau
rosslebeau / gist:60ebbb60d8e288ec7192
Last active August 29, 2015 14:08
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