The Marble Clock

Generalized Marble Clock

Exercise 6 on page 185 describes a novelty clock known as a marble clock. Here are some pictures of such a clock.

The Marble clock in its dust cover --- The current time is 6:33.

Image of Clock in its dust cover



A close up of the Time telling trays --- The current time is also 6:33

close-up image

The Assignment

Your assignment is to implement a generalized marble clock where the capacity of the reservoir, as well as the capacity and number of trays are determined by the user. For example, the "standard" clock pictured above has a reservoir of 27 marbles and trays sizes (top to bottom): 4, 11, 11.

A cycle of the generalized clock begins with all of the marbles in the reservoir (a queue). Marbles are removed from the reservoir and dropped into the clock one at a time. The cycle completes when all of the marbles are back in the reservoir. A cycle of the clock performs a shuffling of the marbles in the reservoir. The program will simulate the behavior of the clock to determine how many cycles are required before the reservoir is back in order. Here are some example runs:

Standard Clock

This program simulates a marble clock.

Enter the tray sizes (top to bottom) separated by spaces: 4 11 11
How many marbles: 27

It took 46 cycles to put the marbles back in order.

A Goofy Clock

This program simulates a marble clock.

Enter the tray sizes (top to bottom) separated by spaces: 5 8 8 4
How many marbles: 31

It took 195 cycles to put the marbles back in order.

Notice, in the first run, we get an answer for the standard clock that differs from the result stated in Exercise 6. That's because our generalized clock always empties a full tray back into the reservoir before the marble that "trips" the tray advances to the next level. That means that the last marble of a cycle with the generalized clock re-enters the reservoir after the marbles from the last tray. The problem in the book assumes that the tripping marble re-enters the reservoir before the marbles from the last tray.

Implementation Notes

For this project you should use the existing Stack.py file for the implementation of Stack, and create a new file linkedq.py containing a linked list implementation of a Queue class. Your program will also use a MarbleClock class.

The MarbleClock class should have methods useful for simulating the behavior of the clock. Here are some suggestions:

__init__(self, traylimits=[4, 11, 11], n=27) -- initializes the clock
dropMarble() -- performs a simulation of dropping 1 marble into the clock
runCycle() -- simulates one complete cycle of the clock
inorder() -- returns True iff all marbles are in the reservoir and in the inital order
You will also probably want to add some helper methods to implement these.