DEV Community

Discussion on: Daily Challenge #144 - Box Office Clerk

Collapse
 
neotamizhan profile image
Siddharth Venkatesan

using Ruby:

def tickets(queue)
  tillbox = []
  can_process = true
  change = { 25 => [], 50 => [25],  100 => [25,50] } 

  queue.each do |bill|
    # if tillbox has the change required
    if (tillbox & change[bill] == change[bill])
      tillbox << bill
      change[bill].each { |b| tillbox.delete_at(tillbox.index(b)) }
    else 
      can_process = false
      break
    end
  end
  can_process
end

puts tickets([25, 25, 50, 50]) #true
puts tickets([25, 50, 25, 100]) #false