aboutsummaryrefslogtreecommitdiff
path: root/challenge-336/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-08-25 10:45:39 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-08-25 10:45:39 +0100
commit778a877423d75f6299c57bb75c3edffd2f304e84 (patch)
tree15d02150e9920c5a72228be60c6436f388c764d8 /challenge-336/eric-cheung/python
parent40ed80c7fb227ddcde0647671dfb803f1a24a4d0 (diff)
downloadperlweeklychallenge-club-778a877423d75f6299c57bb75c3edffd2f304e84.tar.gz
perlweeklychallenge-club-778a877423d75f6299c57bb75c3edffd2f304e84.tar.bz2
perlweeklychallenge-club-778a877423d75f6299c57bb75c3edffd2f304e84.zip
- Added solutions by Bob Lied.
- Added solutions by Mark Anderson. - Added solutions by Jaldhar H. Vyas. - Added solutions by Eric Cheung.
Diffstat (limited to 'challenge-336/eric-cheung/python')
-rwxr-xr-xchallenge-336/eric-cheung/python/ch-1.py14
-rwxr-xr-xchallenge-336/eric-cheung/python/ch-2.py29
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-336/eric-cheung/python/ch-1.py b/challenge-336/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..65adb5c6b2
--- /dev/null
+++ b/challenge-336/eric-cheung/python/ch-1.py
@@ -0,0 +1,14 @@
+
+from math import gcd
+
+## arrInt = [1, 1, 2, 2, 2, 2] ## Example 1
+## arrInt = [1, 1, 1, 2, 2, 2, 3, 3] ## Example 2
+## arrInt = [5, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7] ## Example 3
+## arrInt = [1, 2, 3, 4] ## Example 4
+arrInt = [8, 8, 9, 9, 10, 10, 11, 11] ## Example 5
+
+arrCount = [arrInt.count(nElem) for nElem in set(arrInt)]
+
+nGCD = gcd(*arrCount)
+
+print (nGCD > 1)
diff --git a/challenge-336/eric-cheung/python/ch-2.py b/challenge-336/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..ee0ecf47d2
--- /dev/null
+++ b/challenge-336/eric-cheung/python/ch-2.py
@@ -0,0 +1,29 @@
+
+## arrScore = ["5", "2", "C", "D", "+"] ## Example 1
+## arrScore = ["5", "-2", "4", "C", "D", "9", "+", "+"] ## Example 2
+## arrScore = ["7", "D", "D", "C", "+", "3"] ## Example 3
+## arrScore = ["-5", "-10", "+", "D", "C", "+"] ## Example 4
+arrScore = ["3", "6", "+", "D", "C", "8", "+", "D", "-2", "C", "+"] ## Example 5
+
+nIndx = 0
+while nIndx < len(arrScore):
+ strElem = arrScore[nIndx]
+
+ if "-" in strElem:
+ arrScore[nIndx] = -1 * int(strElem.replace("-", ""))
+ elif strElem.isdigit():
+ arrScore[nIndx] = int(strElem)
+ elif strElem == "+":
+ arrScore[nIndx] = sum(arrScore[nIndx - 2 : nIndx])
+ elif strElem == "C":
+ del arrScore[nIndx]
+ del arrScore[nIndx - 1]
+ nIndx = nIndx - 1
+ continue
+ elif strElem == "D":
+ arrScore[nIndx] = 2 * int(arrScore[nIndx - 1])
+
+ nIndx = nIndx + 1
+
+## print (arrScore)
+print (sum(arrScore))