import matplotlib.pyplot as plt #### #Variabales globales tige1 = [] tige2 = [] tige3 = [] col = ['red', 'green', 'blue', 'orange', 'yellow', 'magenta', 'purple', 'cyan', 'olive', 'gray'] #### def dessin(): plt.axis("square") plt.axis([0, 70, -1, 10]) for k in range(len(tige1)): plt.plot([20-10+tige1[k], 20+10-tige1[k]], [k, k], color = col[tige1[k]]) for k in range(len(tige2)): plt.plot([40-10+tige2[k], 40+10-tige2[k]], [k, k], color = col[tige2[k]]) for k in range(len(tige3)): plt.plot([60-10+tige3[k], 60+10-tige3[k]], [k, k], color = col[tige3[k]]) plt.pause(1) def hanoi(n, deb , mil, fin): """deb : debut fin : fin mil : en utilisant milieu deplace n disque de deb vers fin en utilisant milieu """ if n == 1: a = deb.pop() fin.append(a) dessin() else: #A compléter def lancer_hanoi(n): for k in range(n): tige1.append(k) dessin() hanoi(n, tige1, tige2, tige3) #Simulation lancer_hanoi(4)