Kernel: Python 3 (old Anaconda 3)
Example, i.e., not great, strategy. The elevator starts on the ground floor and moves all the way to the top floor, stopping at every floor in between. When it reaches the top floor, the elevator changes direction and moves all the way back down to the ground floor, again stopping at every floor in between. At every floor where the elevator stops any passengers who want to get off at that floor leave, and any passengers who want to get on enter, as long as there is space in the elevator. If the elevator is full, passengers on that floor have to wait. Upon reaching the ground floor, the elevator repeats the cycle of moving all the way up and all the way down the building.
In [18]:
In [19]:
How many passengers are there?:
How many floors are there?:
Elevator picks up passenger 3 at floor 0
Elevator moves from floor 0 to floor 1
Elevator moves from floor 1 to floor 2
Elevator picks up passenger 1 at floor 2
Elevator drops off passenger 1 at floor 2
Elevator drops off passenger 3 at floor 2
Elevator moves from floor 2 to floor 3
Elevator picks up passenger 2 at floor 3
Elevator drops off passenger 2 at floor 3
Elevator moves from floor 3 to floor 2
Elevator moves from floor 2 to floor 1
Elevator moves from floor 1 to floor 0
Elevator moves from floor 0 to floor 1
Elevator moves from floor 1 to floor 2
Elevator moves from floor 2 to floor 3
Elevator picks up passenger 4 at floor 3
Elevator moves from floor 3 to floor 2
Elevator moves from floor 2 to floor 1
Elevator drops off passenger 4 at floor 1
All passengers have been served - End of simulation
In [0]: