Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fillBus(bus_capacity, ppl):
- if bus_capacity <= 0: return [[]][bus_capacity<0:]
- groups = []
- isValid = lambda x: x not in groups and len(x)<=3
- for n in ppl:
- perms = fillBus(bus_capacity-n, ppl)
- perms and [groups.append(c) for m in perms if isValid(c:=[n, *m])]
- return groups
- ppl = [3,4,5,7,6,2,4,9,8,2]
- print([m for m in fillBus(15, ppl) if len(m)==3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement