Home/ Logo/ Projects/ Skip

Flavius (or Knights) Problem

Screen Shots | Code | Rate this Project | Bottom of Page
Next Section Next Section

Implementation

This solution uses the multiple turtles in MicroWorlds to form the data structure. By using the object nature of MW turtles, their ability to hold their own data and to execute instructions I set up the following program.

Basically we create a doubly linked list of turtles. Each turtle has a pointer to the turtle in front of it and behind it. We then hand a marker (initially set to the skip value) to the first turtle and sit back. The first turtle examines the marker, if it is more then 0 it decrements the marker and hands it to the next turtle which does the same. Eventually a turtle receives the marker when it's value is 0. This turtle then drops itself from the list, resets the marker to the skip value and hands it to the next turtle and so on. When a turtle gets the marker when it is 0 and its links point to itself it is the last turtle standing .

The reason the marker checking routine is called hotpotato is because it resembles the child's game of the same name. In this game an object is passed from child to child while music plays, When the music stops whoever is holding the 'hot potato' is out!

I added some fluff to the basic program. The turtles arrange themselves in a circle and as each turtle drops out of the list it changes it's color. The last turtle sets it color to red. The turtles also keep track of the order they were dropped from the list in.

The complete code listing is here

To Top Next Section To Top To Top Next Section

The Project

Rate this project.

Rate this project.

Previous Top Previous

Home | Top of Page | Logo | Code | Screen Shots | Projects

This page created in part with
Arachnophilia