Given a collection of \(n\) objects with a certain volume. They want transport these objects with as few trucks as possible. All the trucks have the same capacity. The objects have to be loaded on the trucks in such a way that the amount of trucks used is minimal.
Design and implement a greedy algorithm that distributes a collection of objects over as few trucks as possible, where the total capacity of every truck is never exceeded.
Write a Python function pack(items: list, d: int)
. This Python-function takes a list of volumes and a maximum capacity. The function returns a list of filled trucks.
>>> pack([12, 12, 12], 12)
[[12], [12], [12]]
>>> pack([4, 3, 4, 6, 2, 4, 5, 1, 1, 2, 2, 2, 4], 10)
[[6, 4], [5, 4, 1], [4, 4, 2], [3, 2, 2, 2, 1]]
>>> pack([1, 1, 1, 1, 8, 7, 6, 6], 9)
[[8, 1], [7, 1, 1], [6, 1], [6]]