From c5d362da9678bf0e410da99f957c6ad8e72e56bd Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 12 Dec 2023 15:49:30 +0000 Subject: - Added solutions by Mark Anderson. - Added solutions by Thomas Kohler. - Added solutions by Roger Bell_West. - Added solutions by Niels van Dijke. - Added solutions by Peter Campbell Smith. - Added solutions by Peter Meszaros. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan. - Added solutions by PokGoPun. - Added solutions by Laurent Rosenfeld. - Added solutions by Eric Cheung. - Added solutions by Ulrich Rieke. --- challenge-247/eric-cheung/python/ch-1.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 challenge-247/eric-cheung/python/ch-1.py (limited to 'challenge-247/eric-cheung/python/ch-1.py') diff --git a/challenge-247/eric-cheung/python/ch-1.py b/challenge-247/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..d613fb49dd --- /dev/null +++ b/challenge-247/eric-cheung/python/ch-1.py @@ -0,0 +1,31 @@ + +from random import randint + +## Example 1 +arrNames = ["Mr. Wall", "Mrs. Wall", "Mr. Anwar", "Mrs. Anwar", "Mr. Conway", "Mr. Cross"] +nMaxShareFamilyGift = 0 + +## Example 2 +## arrNames = ["Mr. Wall", "Mrs. Wall", "Mr. Anwar"] +## nMaxShareFamilyGift = 1 + +arrGiftFrom = [-1] * len(arrNames) ## List storing the index storing who the gift is sent + +for nIndxLoop, strNameLoop in enumerate(arrNames): + + if nMaxShareFamilyGift == 0: + arrAvailList = [nIndx for nIndx, strLoop in enumerate(arrNames) if strLoop != strNameLoop and strLoop.split(" ")[-1] != strNameLoop.split(" ")[-1] and arrGiftFrom[nIndx] == -1] + else: + arrAvailList = [nIndx for nIndx, strLoop in enumerate(arrNames) if strLoop != strNameLoop and strLoop.split(" ")[-1] == strNameLoop.split(" ")[-1] and arrGiftFrom[nIndx] == -1] + + nMaxShareFamilyGift = nMaxShareFamilyGift - 1 + + nGiftTo = arrAvailList[randint(0, len(arrAvailList) - 1)] + arrGiftFrom[nGiftTo] = nIndxLoop + + print (strNameLoop + " --> " + arrNames[nGiftTo]) + + print ("") + +print ("From : " + " | ".join(arrNames)) +print ("To : " + " | ".join([strNameLoop for nIndxLoop, strNameLoop in sorted(zip(arrGiftFrom, arrNames))])) -- cgit