Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fill_the_box(*args):
- from collections import deque
- box_volume = args[0] * args[1] * args[2]
- new_cubes = deque(args[3:])
- while box_volume and new_cubes:
- current_cube = new_cubes.popleft()
- if current_cube == 'Finish':
- break
- if box_volume - current_cube >= 0:
- box_volume -= current_cube
- else:
- new_cubes.appendleft(current_cube-box_volume)
- box_volume = 0
- if not box_volume:
- return f"No more free space! You have {sum([n for n in new_cubes if str(n).isdigit()])} more cubes."
- else:
- return f"There is free space in the box. You could put {box_volume} more cubes."
- print(fill_the_box(10, 10, 10, 40, "Finish", 2, 15, 30))
Add Comment
Please, Sign In to add comment