Elevator Saga - An Addictive Programming Challenge
Elevator Saga - An Addictive Programming Challenge
Written by Mike James   
Monday, 26 January 2015

Elevators are simple - right? They just go up and down and move people. But if you are a programmer, waiting for one can prompt the thought.could this be done better? The Elevator Saga is a game where you get to schedule their movements. It isn't easy and it is addictive. 

elevatorbanner

 

This is a nice JavaScript simulation of transporting people using one or more elevators. You write the code and the elevators move accordingly. So, for example, the initial program supplied to get you started reads:

{
 init: function(elevators, floors) {
  var elevator = elevators[0];
   // Let's use the first  elevator
  elevator.on("idle", function() {
   // The elevator is idle,
   // so let's go to all the floors   
 
   //(or did we forget one?)
  elevator.goToFloor(0);
  elevator.goToFloor(1);
  });
 },
 update: function(dt, elevators, floors) {
 // We normally don't need to do anything here
 }
}

You supply two functions init, which is called just once at the start; and update, which is called repeatedly. This simple algorithm just sends the elevator to each floor in turn collecting and dropping off passengers.

This algorithm is flawed, as mentioned in the comments, because there are thee floors not just two. The algorithm fails as the elevator slowly clogs up with people needing to get off at the second floor. 

 

elevatorchallenge

 

You are challenged to improve the algorithm to transport the requisite number of people in the given time and when you succeed you can move on to the next challenge. There are no prizes but the intrinsic reward is in showing that you can invent an algorithm that works. It would also be a possible way of introducing someone to programming but only with some additional help.  

Notice that the passengers don't indicate to the elevator the floor they want to get to just up or down. In real life entering an elevator without floor buttons is worrying to passengers so it tends not to be used but it is efficient.

The question is how efficient?

Later on you get to work with multiple elevators as well and then it gets really interesting.

 

elevatoricon

 

You can discover the full API that you can use in constructing an algorithm on the challenge web site, but if you are interested in some theory Sharpen your Coding Skills - Elevator Puzzle to find out about Karp's Algorithm. 

 

More Information

Elevator Saga

Related Articles

Sharpen your Coding Skills - Elevator Puzzle

The XY Traveling Salesman Problem Solved

An Envy-Free Algorithm

Speed Data Is Enough To Track You

 

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

Banner


Canada's RAND Immigration Lottery Not Random!
17/06/2018

Well of course it isn't, but that doesn't stop people who should no better from stirring up a mock disgust and alarm. Oh dear we programmers are at it again, cutting corners with our job lot of not-qu [ ... ]



The GNOME Foundation Is Hiring
10/07/2018

Thanks to a donation of up to $1,000,000 over the next two years the GNOME Foundation is recruiting for four positions including one for a core developer of the GTK+ toolkit and another for  [ ... ]


More News

 

justjsquare

 



 

Comments




or email your comment to: comments@i-programmer.info

 

Last Updated ( Monday, 26 January 2015 )
 
 

   
Banner
RSS feed of news items only
I Programmer News
Copyright © 2018 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.