Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created November 21, 2019 17:52
Show Gist options
  • Select an option

  • Save venelrene/f2e6c4148bb6140e1a96957d4804383c to your computer and use it in GitHub Desktop.

Select an option

Save venelrene/f2e6c4148bb6140e1a96957d4804383c to your computer and use it in GitHub Desktop.
There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out!
def queue_time(customers, n)
registers = Array.new(n, 0)
while !customers.empty?
idx = registers.index(registers.min)
registers[idx] += customers.shift unless customers.empty?
end
registers.max
# if I had to do it in one line
# customers.each{|time| registers[registers.index(registers.min)] = (time + registers.min)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment