The elevator game is a little thought experiment. It is not new, in fact Elevator Saga is another fun one. This one was just based on whatever came out of my head to see what would happen.

Here are the rules:

  • There is one elevator in a building that has 10 floors.
  • There are 30 passengers to transport. 15 passengers from level 1 to another floor and 15 passengers from a higher floor to level 1. However, they are all shuffled together.
  • There are up to 5 people waiting for the elevator at any given time.
  • The game is repeatable (all the same passengers going to the same place).
  • For each floor the elevator moves will be one point.
  • The goal is to transport everyone with the lowest final score.

How to Play

To actually play (run) it you can download the Python file in this gist.

The engine is not particularly well written in terms of clean code, it’s just what fell out as I was coding. What’s important is the elevatorfunction:

def elevator(building):
for person in building.people:
if person.status == Person.WAITING and \
person.from_floor != building.elevator_floor:
if person.status == Person.IN_ELEVATOR:

It is a very rudimentary algorithm that can be clearly improved. As a starting point that works it scores 183.

The script animates all the lift activity and you an change the speed by alerting how long it sleeps between each floor.

Image for post
Image for post

On the far left is the floor number, followed by an icon that indicates if there is at least one person waiting for the elevator at that floor.

The number in the box represents the elevator itself. The number is how many passengers are currently in the elevator.

The person icons on the right show passengers that have got off at their destination floor.

I hope you have fun beating my score! :)

Originally published at on September 10, 2016.

Written by

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store