From d56516931ff47977da31018af44a97a68aee8c82 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 25 Nov 2021 19:49:17 +0100 Subject: [PATCH] =?UTF-8?q?Joyeux=20No=C3=ABl=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tirkdo.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tirkdo.py diff --git a/tirkdo.py b/tirkdo.py new file mode 100644 index 0000000..91633e7 --- /dev/null +++ b/tirkdo.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +import random + +participants = [ + 'Maman', + 'Papa', + 'Mémé', + 'Charlotte', + 'Nico', + 'Didi', + 'Johnny', + 'Ben', + 'Ludo', +] + +participants_recois = participants.copy() + +on_evite = { + 'Ben': 'Ludo', + 'Charlotte': 'Nico', + 'Maman': 'Papa', + 'Didi': 'Johnny', +} + +# On mélange les listes +random.shuffle(participants) +random.shuffle(participants_recois) + +# On procède au tirage +tirage = dict() +for offre in participants: + while True: + recois = random.choice(participants_recois) + + # Pas à soi même + if recois == offre: + continue + # On évite entre couple + if on_evite.get(offre) == recois or on_evite.get(recois) == offre: + continue + + # Trouvé ! + tirage[offre] = recois + participants_recois.remove(recois) + break + + +print("Résultat du tirage :") +for offre, recois in tirage.items(): + print(" - %s -> %s" % (offre, recois))