Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def try_to_make_viable_path(cloned_items, cloned_deposits)
- path = []
- booked_deposits = {} # deposit_id => qty
- cloned_items.each_pair do |item_id, qty|
- qty.times do
- _deposits = cloned_deposits[item_id]
- _available_deposits = _deposits.select{|x| x.quantity > booked_deposits.fetch(x.id){0}}
- _lucky_deposit = _available_deposits.sample
- booked_deposits[_lucky_deposit.id] = booked_deposits.fetch(_lucky_deposit.id){0} + 1
- path << _lucky_deposit.vertex
- end
- end
- if !is_viable_path?(path)
- puts "Неживой путь #{path.inspect}"
- end
- path
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement