At a depot, parcels come off the belt one at a time and are loaded straight into vans. Every van can carry at most capacity kilograms. The loaders follow one rule: put the parcel into the first van, in the order the vans were opened, that still has enough room for it; if no open van has room, open a new van for it. Vans are never closed.
Write load_vans(parcels, capacity) that returns the loads of all vans, in the order they were opened, each load being the list of parcel weights in the order they went in.
The helper parcel_run(n, capacity, seed) returns n random parcel weights.
Examples
Input: parcels = [4, 8, 1, 4, 2, 1], capacity = 10
Output: [[4, 1, 4, 1], [8, 2]]
Explanation: 8 does not fit next to 4 (6 kg of room), so van 2 opens. The 2 does
not fit into van 1 (1 kg left) but fits exactly into van 2.
Input: parcels = [], capacity = 5
Output: []
Constraints
0 <= len(parcels) <= 10001 <= capacity <= 1000and every parcel weighs between1andcapacitykilograms
Goals
- Use for ... else for 'searched every van and none had room'
- Keep a list of lists and append to the right inner list