tower hanoi

The Tower of Hanoi puzzle is a classic in studying planning in children and adults (see references).

In this puzzle, participants need to move discs from the left peg to the right peg (see image on the right). There are two constraints;

  1. Larger discs are not allowed to be placed on smaller discs.

  2. Discs shall be moved one at the time.

About this implementation

This uses new features, available from version 3.3.0.

In this example, there are three pegs with only three discs. These three discs can be moved to the goal in as little as 7 steps.

In this experiment, each "trial" is actually just one step. After each move by the participant, the time used so far as well as the total steps is save.

It is possible to save more information, but for simplicity that is not done here.

Run the demo

Data output file

In PsyToolkit, the data output file is simply a textfile. The save line of the PsyToolkit experiment script determines what is being saved in the data output file. Typically, for each experimental trial, you would have exactly one line in your text file, and each number/word on that line gives you the information you need for your data analysis, such as the condition, response speed, and whether an error was made.

Meaning of the columns in the output datafile. You need this information for your data analysis.

Colum Meaning


Time spent so far in milliseconds


Counter of steps (possible steps)


Number attempts so far to put bigger on smaller disc


Number of attempts to move disc somewhere where it cannot be (e.g., in the air, and it snaps back)

The last line in the data file will give you all the information you really want, namely the number of steps and the numbers of mistakes made.


If you have a PsyToolkit account, you can upload the zipfile directly to your PsyToolkit account. Watch a video on how to do that. If you want to upload the zipfile into your PsyToolkit account, make sure the file is not automatically uncompressed (some browsers, especially Mac Safari, by default uncompress zip files). Read here how to easily deal with this.

Further reading

  • Byrnes, M.M. & Spitz, H.H. (1979). Developmental progression of performance on the Tower of Hanoi problem. Bulletin of the Psychonomic Society, 14 (5), 379-381. (Publisher link)

  • Davis, H.P., Klebe, K.J. (2001). A longitudinal study of the performance of the elderly and the young on the Tower of Hanoi Puzzle and Rey Recall. Brain and Cognition, 46, 95-99. (Publisher link)

  • Schiff, R. & Vakil, E. Age differences in cognitive skill learning, retention and transfer: The case of the Tower of Hanoi Puzzle. Learning and Individual Differences, 39, 164-171. (Publisher link)