Skip to content

Instantly share code, notes, and snippets.

View Onikoroshi's full-sized avatar

Peter T Cormack Onikoroshi

View GitHub Profile
@Onikoroshi
Onikoroshi / truck_priority.rb
Created February 17, 2018 19:41
distribute prioritization
destinations = [
{ priority: 1, destination_id: "A", trucks: 2, still_needed: 2 },
{ priority: 2, destination_id: "B", trucks: 2, still_needed: 2 },
{ priority: 3, destination_id: "C", trucks: 1, still_needed: 1 }
]
def next_destination
# reset if everyone has been fully supplied
if destinations.select{|dest| dest[:still_needed] == 0}.count == destinations.count
destinations.map{|dest| dest[:still_needed] = dest[:trucks]}