Advertisement
Mussab_Blue

Fill The Bus

Jul 19th, 2022 (edited)
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. def fillBus(bus_capacity, ppl):
  2.     if bus_capacity <= 0: return [[]][bus_capacity<0:]
  3.  
  4.     groups = []
  5.     isValid = lambda x: x not in groups and len(x)<=3
  6.  
  7.     for n in ppl:
  8.         perms = fillBus(bus_capacity-n, ppl)    
  9.         perms and [groups.append(c) for m in perms if isValid(c:=[n, *m])]
  10.     return groups
  11.    
  12. ppl = [3,4,5,7,6,2,4,9,8,2]
  13. print([m for m in fillBus(15, ppl) if len(m)==3])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement