aboutsummaryrefslogtreecommitdiff
path: root/challenge-335/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-08-19 12:12:35 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-08-19 12:12:35 +0100
commit72115ca8dee469436857991c88d7002158725057 (patch)
tree2df87ae4691a937a254afbf644c9e35fb9ae7a0b /challenge-335/eric-cheung/python
parent8927d878c6aa164b979634439ee01f92790cd64b (diff)
downloadperlweeklychallenge-club-72115ca8dee469436857991c88d7002158725057.tar.gz
perlweeklychallenge-club-72115ca8dee469436857991c88d7002158725057.tar.bz2
perlweeklychallenge-club-72115ca8dee469436857991c88d7002158725057.zip
- Added solutions by Eric Cheung.
- Added solutions by Jan Krnavek. - Added solutions by Andrew Shitov. - Added solutions by Mark Anderson. - Added solutions by E. Choroba. - Added solutions by Simon Proctor. - Added solutions by Andreas Mahnke. - Added solutions by Feng Chang. - Added solutions by PokGoPun. - Added solutions by Wanderdoc. - Added solutions by Thomas Kohler. - Added solutions by Conor Hoekstra. - Added solutions by Ali Moradi. - Added solutions by W. Luis Mochan.
Diffstat (limited to 'challenge-335/eric-cheung/python')
-rwxr-xr-xchallenge-335/eric-cheung/python/ch-1.py25
-rwxr-xr-xchallenge-335/eric-cheung/python/ch-2.py31
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-335/eric-cheung/python/ch-1.py b/challenge-335/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..15e9cde07a
--- /dev/null
+++ b/challenge-335/eric-cheung/python/ch-1.py
@@ -0,0 +1,25 @@
+
+## arrWords = ["bella", "label", "roller"] ## Example 1
+## arrWords = ["cool", "lock", "cook"] ## Example 2
+## arrWords = ["hello", "world", "pole"] ## Example 3
+## arrWords = ["abc", "def", "ghi"] ## Example 4
+arrWords = ["aab", "aac", "aaa"] ## Example 5
+
+arrOutput = []
+
+for charLoop in set(arrWords[0]):
+ bFound = True
+
+ for strLoop in arrWords[1:]:
+ if charLoop not in strLoop:
+ bFound = False
+ break
+
+ if not bFound:
+ continue
+
+ nCount = min([strLoop.count(charLoop) for strLoop in arrWords])
+
+ arrOutput = arrOutput + list(charLoop * nCount)
+
+print (arrOutput)
diff --git a/challenge-335/eric-cheung/python/ch-2.py b/challenge-335/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..2c3c9ea545
--- /dev/null
+++ b/challenge-335/eric-cheung/python/ch-2.py
@@ -0,0 +1,31 @@
+
+def PlayerWin(arrInput, nNumMove):
+ for nRow in range(3):
+ if len(set([arrInput[nRow][nCol] for nCol in range(3)])) == 1 and arrInput[nRow][nRow] in ["A", "B"]:
+ return arrInput[nRow][nRow]
+
+ for nCol in range(3):
+ if len(set([arrInput[nRow][nCol] for nRow in range(3)])) == 1 and arrInput[nCol][nCol] in ["A", "B"]:
+ return arrInput[nCol][nCol]
+
+ if len(set([arrInput[nMax][nMax] for nMax in range(3)])) == 1 and arrInput[1][1] in ["A", "B"]:
+ return arrInput[1][1]
+
+ if len(set([arrInput[nMax][2 - nMax] for nMax in range(3)])) == 1 and arrInput[1][1] in ["A", "B"]:
+ return arrInput[1][1]
+
+ return ("Draw" if nNumMove == 9 else "Pending")
+
+## arrMoves = [[0, 0], [2, 0], [1, 1], [2, 1], [2, 2]] ## Example 1
+## arrMoves = [[0, 0], [1, 1], [0, 1], [0, 2], [1, 0], [2, 0]] ## Example 2
+## arrMoves = [[0, 0], [1, 1], [2, 0], [1, 0], [1, 2], [2, 1], [0, 1], [0, 2], [2, 2]] ## Example 3
+## arrMoves = [[0, 0], [1, 1]] ## Example 4
+arrMoves = [[1, 1], [0, 0], [2, 2], [0, 1], [1, 0], [0, 2]] ## Example 5
+
+arrOutput = [["_", "_", "_"], ["_", "_", "_"], ["_", "_", "_"]]
+
+for nIndx, arrLoop in enumerate(arrMoves):
+ arrOutput[arrLoop[0]][arrLoop[1]] = ("A" if nIndx % 2 == 0 else "B")
+
+## print (arrOutput)
+print (PlayerWin(arrOutput, len(arrMoves)))