from collections import deque
bridge_length, weight_limit, truck_weights = 2, 10, [7, 4, 5, 6]
bridge = deque([0] * bridge_length)
current_weight = 0
time = 0
for truck in truck_weights:
while True:
current_weight -= bridge.popleft()
time += 1
if current_weight + truck <= weight_limit:
bridge.append(truck)
current_weight += truck
break
else:
bridge.append(0)
time += bridge_length
print(time)
To embed this project on your website, copy the following code and paste it into your website's HTML: