viligen

fill_the_box

Jan 26th, 2022 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. def fill_the_box(*args):
  2.     from collections import deque
  3.     box_volume = args[0] * args[1] * args[2]
  4.     new_cubes = deque(args[3:])
  5.  
  6.     while box_volume and new_cubes:
  7.         current_cube = new_cubes.popleft()
  8.         if current_cube == 'Finish':
  9.             break
  10.         if box_volume - current_cube >= 0:
  11.             box_volume -= current_cube
  12.         else:
  13.             new_cubes.appendleft(current_cube-box_volume)
  14.             box_volume = 0
  15.  
  16.     if not box_volume:
  17.         return f"No more free space! You have {sum([n for n in new_cubes if str(n).isdigit()])} more cubes."
  18.     else:
  19.         return f"There is free space in the box. You could put {box_volume} more cubes."
  20.  
  21.  
  22. print(fill_the_box(10, 10, 10, 40, "Finish", 2, 15, 30))
Add Comment
Please, Sign In to add comment