This is a simple puzzle, containing n disks of different sizes and 3 poles. The objective of the puzzle is to move the entire stack from the starting pole to the goal pole, obeying the following simple rules: (1) Only one disk can be moved at a time. (2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. (3) No disk may be placed on top of a smaller disk.
A romantic legend manufactured by Edouard Lucas as an accompaniment to the popular game he invented, the Tower of Hanoi. According to the tale of the Tower of Brahma, in the Indian city of Benares, beneath a dome that marked the center of the world, is to be found a brass plate in which are set three diamond needles, ”each a cubit high and as thick as the body of a bee.” Brahma placed 64 disks of pure gold on one of these needles at the time of Creation. Each disk is a different size, and each is placed so that it rests on top of another disk of greater size, with the largest resting on the brass plate at the bottom and the smallest at the top. Within the temple are priests whose job it is to transfer all the gold disks from their original needle to one of the others, without ever moving more than one disk at a time. No priest can ever place any disk on top of a smaller one, or anywhere else except on one of the needles. When the task is done, and all 64 disks have been successfully transferred to another needle, ”tower, temple, and Brahmins alike will crumble into dust, and with a thunder-clap the world will vanish.” The pre- diction (thunder-clap aside) seems fairly safe given that the number of steps required to transfer all the disks is 2 64 − 1, which is approximately 1.8447 ∗ 10 19 . Assuming one second per move, this would take about five times longer than the current age of the universe!
(Source: http://www.daviddarling.info/encyclopedia/T/Tower_of_Brahma.html)
In the following is a short description of two paradigms which were experimented on.
When undergoing the Think Aloud experiment with the Object-oriented programming paradigm (using the language Java) subjects firstly set up the internal representation of the problem space using programmable objects. Afterwards, some form of graph theory was implemented - stable states were identified (positions of disks on poles) and moves between them. As the problem space was set up, some search algorithm (usually depth search) was executed over the problem graph, that produced the end solution. Solutions obtained this way were sub-optimal, but the physical representation was very clear and though the code was long (mean: 120 lines of code) and it took long time (average: 2.8
hours) to produce, it was subjectively easily readable.
When undergoing the same experiment with the Logic programming paradigm (using the language Prolog), the initial process of designing the code took longer, but the whole programming process was concluded in a much shorter time. The idea subjects used here was double recursion (to move unwanted disks away) and a move of the desired disk. This procedure produces an optimal solution in an shorter period of time (average: 28 minutes) and with less written code (mean: 22 lines of code) compared to the Object oriented programming paradigm, however the code is subjectively much harder to read.
For better understanding, two Java implementations are following, one for each representation used.
Object-oriented programming paradigm |
Logic programming paradigm |
public class TowerOfHanoi } |
public class MainClass { |