
Move_disks(n - i, intermediate, intermediate2, source, destination) Move_disks(1, source, intermediate, intermediate2, destination) Move_disks(n - i, source, intermediate 2 destination, intermediate) """Move n disks from source to int int int int int None Since there are 4 possible sources and destinations, in my own function I have 5 arguments instead of 4: def move_disks(n, source, intermediate, intermediate2, destination): Manually playing around with disks and towers I got n-i = 2 if n>=3 and i = 1 if n =2. Move n-i smallest disks from intermediate tower to destination tower.Move i disks from the original tower to the destination tower, using only three available towers.Move n- i disks to intermediate stool using all four towers.

Now for four stools, I'm given the following: Move_disks(n - 1, intermediate, source, destination) Move_disks(1, source, intermediate, destination) Move_disks(n - 1, source, destination, intermediate) """Move n disks from source to int int int int None
#HANOI TOWERS MOVE ALGORITHM CODE#
The actual code for this algorithm (with model being of class Model which has towers and disks, with a move method that moves disks from one tower to another) yields: def move_disks(n, source, intermediate, destination):

I'm having a decent amount of trouble implementing the optimal algorithm for the tower of hanoi game for four stools in python.įirst, in class we solved the tower of hanoi algorithm for three towers, for which we were given the following algorithm:
