loading...

re: Daily Challenge #17 - Double Trouble VIEW POST

FULL DISCUSSION
 

Ruby.

def drinker(queue = [], nth = 1)
  drinker = nil
  can = 0
  while can < nth
    drinker = queue.shift
    drinker = {name: drinker, arity: 1} unless drinker.is_a?(Hash)
    can += drinker[:arity]
    drinker[:arity] *= 2
    queue << drinker
  end

  drinker[:name]
end
code of conduct - report abuse