aboutsummaryrefslogtreecommitdiff
path: root/challenge-247/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-12-12 15:49:30 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-12-12 15:49:30 +0000
commitc5d362da9678bf0e410da99f957c6ad8e72e56bd (patch)
tree6ad038a2987222b9e1a9c18b1307f688a810602c /challenge-247/eric-cheung/python
parent024ced642f56003a51fe61164cdc9598219c3f4d (diff)
downloadperlweeklychallenge-club-c5d362da9678bf0e410da99f957c6ad8e72e56bd.tar.gz
perlweeklychallenge-club-c5d362da9678bf0e410da99f957c6ad8e72e56bd.tar.bz2
perlweeklychallenge-club-c5d362da9678bf0e410da99f957c6ad8e72e56bd.zip
- 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.
Diffstat (limited to 'challenge-247/eric-cheung/python')
-rwxr-xr-xchallenge-247/eric-cheung/python/ch-1.py31
-rwxr-xr-xchallenge-247/eric-cheung/python/ch-2.py12
2 files changed, 43 insertions, 0 deletions
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))]))
diff --git a/challenge-247/eric-cheung/python/ch-2.py b/challenge-247/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..61a6df3724
--- /dev/null
+++ b/challenge-247/eric-cheung/python/ch-2.py
@@ -0,0 +1,12 @@
+
+## strInput = "abcdbca" ## Example 1
+strInput = "cdeabeabfcdfabgcd" ## Example 2
+
+arrPairStr = [strInput[nIndxLoop : nIndxLoop + 2] for nIndxLoop in range(len(strInput) - 1)]
+
+arrUniqPair = list(set(arrPairStr))
+arrCountPair = [arrPairStr.count(strLoop) for strLoop in arrUniqPair]
+
+arrMaxPair = sorted([arrUniqPair[nIndx] for nIndx in range(len(arrCountPair)) if arrCountPair[nIndx] == max(arrCountPair)])
+
+print (arrMaxPair[0])