• [^] # Re: python, en trichant

    Posté par (Mastodon) . En réponse au message Avent du Code, jour 13. Évalué à 2.

    On peut faire un truc rigolo sur la partie travail, on garde packet et input() identiques, et on reste sur du générateur/itérateur jusqu'à la fin avec le sort :

    def analyse(decoder):
     score = 0
     for id, (a, b) in enumerate(input()):
     yield a
     yield b
     if a <= b:
     score += id + 1
     print(f"Pairs in the right order : {score}")
     for d in decoder:
     yield d
    decoder = [packet([[2]]), packet([[6]])]
    s = sorted(analyse(decoder))
    print(f"Decoder Key = {(s.index(decoder[0])+1) * (s.index(decoder[1])+1)}")
    • Yth, pour le fun...