CoddityTeam / movaicode

Concours mensuel du Pire Développeur de France
123 stars 10 forks source link

Taillage de matroustaches #253

Open HugoooM opened 1 year ago

HugoooM commented 1 year ago

Voilà ma solution, pour tailler n'importe quelle matroustache. Après une réflexion de plusieurs jours pour résoudre ce problème extrêmement dur, voici ma solution. Mon code est très optimisé, je pense même que ce n'est pas possible de le rendre plus optimisé. Ce programme est aussi l'occasion d'en apprendre plus sur les différents styles de matroustache qui existent !

import random

matroustache_reelle = [[10, 10, 10, 15, 10, 12, 10, 11, 10, 10],
                       [9, 12, 9, 9, 9, 9, 10, 9, 9, 9],
                       [8, 8, 10, 8, 9, 8, 8, 8, 10, 8],
                       [7, 7, 7, 7, 10, 7, 7, 9, 8, 7],
                       [6, 6, 7, 9, 8, 6, 6, 6, 8, 6],
                       [5, 5, 6, 7, 8, 5, 10, 9, 5, 6]]

def taille_de_stache(matroustache_reelle):
    un = 1

    # On rase tout pour repartir sur de bonnes bases
    for i in range(len(matroustache_reelle) - 1, -1, -1):
        for j in range(len(matroustache_reelle[i]) - 1, -1, -1):
            while matroustache_reelle[i][j] != 0:
                matroustache_reelle[i][j] -= 1

    # Maintenant que la matroustache est entièrement rasée
    # Profitons-en pour en apprendre un peu plus sur les nombreuses formes de matroustaches

    # La matroustache en croc est une matroustache très relevée faisant penser à une paire d'antennes, qui est souvent appelée matroustache de Dali.
    matroustacheEnCroc = [[0, 0, 10, 0, 0, 0, 0, 10, 0, 0],
                          [0, 9, 9, 0, 0, 0, 0, 9, 9, 0],
                          [0, 8, 0, 0, 0, 0, 0, 0, 8, 0],
                          [7, 0, 0, 0, 0, 0, 0, 0, 0, 7],
                          [6, 0, 0, 0, 0, 0, 0, 0, 0, 6],
                          [0, 5, 5, 0, 0, 0, 0, 5, 5, 0]]

    # La très connue matroustache de John Waters. Très fine, très élégante.
    matroustacheEnTraitDeCrayon = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                   [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
                                   [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]]

    # La matroustache de Jeff Tuche... J'ai pas trouvé de compliment pour celle-ci.
    matroustacheEnFerACheval = [[10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
                                [9, 9, 0, 0, 0, 0, 0, 0, 9, 9],
                                [8, 8, 0, 0, 0, 0, 0, 0, 8, 8],
                                [7, 7, 0, 0, 0, 0, 0, 0, 7, 7],
                                [6, 6, 0, 0, 0, 0, 0, 0, 6, 6],
                                [5, 5, 0, 0, 0, 0, 0, 0, 5, 5]]

    # Une matroustache en guidon est une matroustache dont les extrémités sont suffisamment longues pour être recourbées.
    matroustacheEnGuidon = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                            [0, 0, 9, 0, 0, 0, 0, 9, 0, 0],
                            [0, 8, 0, 8, 0, 0, 8, 0, 8, 0],
                            [0, 7, 0, 0, 0, 0, 0, 0, 7, 0],
                            [0, 0, 6, 6, 6, 6, 6, 6, 0, 0],
                            [0, 0, 0, 5, 5, 5, 5, 0, 0, 0]]

    # Une matroustache chevron présente une forme descendant vers le bas et vers les commissures de la bouche.
    matroustacheEnChevron = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                             [0, 0, 8, 8, 0, 0, 8, 8, 0, 0],
                             [0, 7, 7, 7, 7, 7, 7, 7, 7, 0],
                             [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
                             [5, 0, 5, 0, 5, 0, 5, 0, 5, 0]]

    # La matroustache de Charlie Chaplin. Selon wikipédia elle a une forme de brosse à dents.
    matroustacheEnBrosseADent = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 9, 9, 9, 9, 9, 9, 0, 0],
                                 [0, 0, 8, 8, 8, 8, 8, 8, 0, 0],
                                 [0, 0, 7, 7, 7, 7, 7, 7, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

    leDicoDesmatroustaches = {"matroustache en croc": matroustacheEnCroc,
                              "matroustache en trait de crayon": matroustacheEnTraitDeCrayon,
                              "matroustache en fer à cheval": matroustacheEnFerACheval,
                              "matroustache en guidon": matroustacheEnGuidon,
                              "matroustache en chevron": matroustacheEnChevron,
                              "matroustache en brosse à dent": matroustacheEnBrosseADent}

    laListeDesmatroustaches = ["matroustache en croc", "matroustache en trait de crayon",
                               "matroustache en fer à cheval",
                               "matroustache en guidon", "matroustache en chevron", "matroustache en brosse à dent"]

    for i in laListeDesmatroustaches:
        for j in range(len(matroustache_reelle) - 1, -1, -1):
            for k in range(len(matroustache_reelle[j]) - 1, -1, -1):
                if (matroustache_reelle[j][k] == 0):
                    matroustache_reelle[j][k] = leDicoDesmatroustaches[i][j][k]

    # Malheureusement la matroustache a déjà commencé à pousser :(
    # On doit donc retailler cette matroustache.
    for i in range(0, random.randint(0, len(matroustache_reelle) * len(matroustache_reelle[0]))):
        matroustache_reelle[random.randint(0, len(matroustache_reelle) - 1)][
            random.randint(0, len(matroustache_reelle[0]) - 1)] += 1

    longueurDePoil = 5

    for i in range(len(matroustache_reelle) - 1, -1, -1):
        for j in range(len(matroustache_reelle[i]) - 1, -1, -1):
            if matroustache_reelle[i][j] != longueurDePoil:
                matroustache_reelle[i][j] = longueurDePoil
        longueurDePoil += un

    return matroustache_reelle