Hi, i am Sadie
Pleace need some help in python Hanoï algorithme.
When i run test i still have this in console:
hanoi_solver(n) should solve the tower of Hanoi puzzle for any positive value of n.
// tests completed
How to correct it.
rod_1= [ ]
rod_2 = [ ]
rod_3 = [ ]
im_rod1 = [ ]
empty_rod = “[ ]”
state = [ ]
mvt = 0
def hanoi_solver(n):
def init_rod(n):
global rod_1
global rod_2
global rod_3
global im_rod1
for elt in range(1,n+1):
rod_1.append(elt)
rod_1.sort(reverse=True)
im_rod1 = rod_1[:]
state.append([rod_1[:],rod_2[:],rod_3[:]])
def play_rod(rod,source_rod,inter_rod,destination_rod):
global mvt
if rod == 1:
# move disc from source to destination
destination_rod.append(source_rod.pop())
mvt+=1
state.append([rod_1[:],rod_2[:],rod_3[:]])
else:
play_rod(rod - 1,source_rod,destination_rod,inter_rod)
# move disc from source to destination
destination_rod.append(source_rod.pop())
mvt+=1
state.append([rod_1[:],rod_2[:],rod_3[:]])
play_rod(rod - 1,inter_rod,source_rod,destination_rod)
init_rod(n)
play_rod(n,rod_1,rod_2,rod_3)
data = [" ".join(map(str,sublist)) for sublist in state]
data1 = '\n'.join(data)
return data1