So far i know how to do the tower of Hanoi with 3 towers, but i have no idea on how to implement the Frame Steward Algorithm for 4 towers.
this is how my current three tower function looks like.
def move_three_towers(n, from_tower, to_tower, spare_tower):
if (n > 0):
move_three_towers(n-1, from_tower, spare_tower, to_tower)
print(from_tower, ' --> ', to_tower)
move_three_towers(n-1, spare_tower, to_tower, from_tower)
i need help implementing n - k disks to another tower using 4 towers. for some 1 ≤ k < n
here is my attempt at the algorithm but it doesn't work, please help.
def move_four_towers(n, k = 0, from_tower, to_tower, spare_tower1, spare_tower2):
if n == 1:
print(from_tower, ' --> ', to_tower)
if n > 1:
move_four_towers(n - k, from_tower, spare_tower2, spare_tower1, to_tower)
print(from_tower, ' --> ', to_tower)
move_three_towers(k, from_tower, to_tower, spare_tower1)
move_four_towers(n - k, spare_tower2, to_tower, spare_tower1, from_tower)