correction_erreur_xml.py

Created by joelkouakou2080

Created on March 22, 2024

1.29 KB


from kandinsky import *

def hanoi(n, depart="A", intermediaire="B", arrive="C"):
    if n == 1:
        print("Déplacer le disque de", depart, "vers", arrive)
    else:
        hanoi(n - 1, depart, arrive, intermediaire)
        print("Déplacer le disque de", depart, "vers", arrive)
        hanoi(n - 1, intermediaire, depart, arrive)

def rapide_hanoi(n):
    return (2**n) - 1

def draw_hanoi(n):
    screen.clear()
    screen.draw_string("Résolution du problème des tours de Hanoï", 10, 10)
    screen.draw_string("Nombre de disques : " + str(n), 10, 30)
    screen.draw_string("Nombre minimum de mouvements : " + str(rapide_hanoi(n)), 10, 50)
    screen.draw_string("Étapes de résolution :", 10, 70)
    hanoi_steps = []

    def hanoi(n, depart="A", intermediaire="B", arrive="C"):
        if n == 1:
            hanoi_steps.append("Déplacer le disque de {} vers {}".format(depart, arrive))
        else:
            hanoi(n - 1, depart, arrive, intermediaire)
            hanoi_steps.append("Déplacer le disque de {} vers {}".format(depart, arrive))
            hanoi(n - 1, intermediaire, depart, arrive)

    hanoi(n)
    
    y_offset = 90
    for step in hanoi_steps:
        screen.draw_string(step, 10, y_offset)
        y_offset += 20

screen = Screen()
draw_hanoi(3)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.