Tower of Hanoi

61 views
Skip to first unread message

Alexey Perekhodov

unread,
Feb 17, 2020, 3:54:04 AM2/17/20
to 4Clojure
I proposed a new problem -- the Tower of Hanoi.

If you are not familiar with the underlying puzzle, it consists of three rods and disks of different sizes on them. You can slide a disk from one rod to another, but at any moment on any rod disks should be in ascending order with smaller disk on the top of the rod. The objective of the puzzle is to move all disks from one rod to another.

In our task the Hanoi tower is represented with a vector of three vectors of numbers. Each nested vector represents one of the three towers, upper disk is at the beginning of the vector. The goal of the problem is to move the tower with the given number of disks from the first rod to the last rod with minimum moves. The solution should be the vector (or sequence) of towers after each move. As an example, with the three disks, the solution would be:
[[[1 2 3] [     ] [     ]]
 [[  2 3] [     ] [    1]]
 [[    3] [    2] [    1]]
 [[    3] [  1 2] [     ]]
 [[     ] [  1 2] [    3]]
 [[    1] [    2] [    3]]
 [[    1] [     ] [  2 3]]
 [[     ] [     ] [1 2 3]]]

I supplied the problem with use cases and even a sample solution. The solution was about 15 lines of spare code, not too complicated, obviously.

However, the problem was not published. Can anyone suppose why?

Alexey Perekhodov

unread,
Feb 17, 2020, 7:53:42 AM2/17/20
to 4Clojure
In case you are not familiar with the puzzle there are also numerous corresponding online games.
Here is one of them.

Reply all
Reply to author
Forward
0 new messages