Catalog · How the catalog works
tower_of_hanoi
Tower of Hanoi Solver in Pascal
- ★ 1 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
Tower of Hanoi Solver
What is it?
The Tower of Hanoi problem consists of 3 rods and N discs of different sizes. Roughly, the goal of the problem is to move the stack of discs from the leftmost rod to the rightmost rod. However, as all problems, some rules have to be followed:
- We can only move one disc at a time
- We can also only move a disc if it is the uppermost disc on a stack
- Finally, we cannot place a larger disc on top of a smaller one. In other words, we will always need to have cone-shape towers
So, the simple example shown in the figure below.

We can see that 7 steps were required to solve this simple example. This corresponds to 2^n - 1
You can try to solve this problem by yourself here.
About Solver
You need to have fpc (Free Pascal Compiler) for compiling hanoi.pas file.
Linux
sudo apt-get install fpcMacOS
sudo port install fpcCompile and run program with
make
./hanoi Nwhere N is number of discs.
Result is like this

Delete the executable file with command
make clean
