Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.63 KB | None | 0 0
  1.   def try_to_make_viable_path(cloned_items, cloned_deposits)
  2.     path = []
  3.     booked_deposits = {} # deposit_id => qty
  4.     cloned_items.each_pair do |item_id, qty|
  5.       qty.times do
  6.         _deposits = cloned_deposits[item_id]
  7.         _available_deposits = _deposits.select{|x| x.quantity > booked_deposits.fetch(x.id){0}}
  8.         _lucky_deposit = _available_deposits.sample
  9.         booked_deposits[_lucky_deposit.id] = booked_deposits.fetch(_lucky_deposit.id){0} + 1
  10.         path << _lucky_deposit.vertex
  11.       end
  12.     end
  13.     if !is_viable_path?(path)
  14.       puts "Неживой путь #{path.inspect}"
  15.     end
  16.     path
  17.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement