From 778a877423d75f6299c57bb75c3edffd2f304e84 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Mon, 25 Aug 2025 10:45:39 +0100 Subject: - Added solutions by Bob Lied. - Added solutions by Mark Anderson. - Added solutions by Jaldhar H. Vyas. - Added solutions by Eric Cheung. --- challenge-336/eric-cheung/python/ch-1.py | 14 ++++++++++++++ challenge-336/eric-cheung/python/ch-2.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 challenge-336/eric-cheung/python/ch-1.py create mode 100755 challenge-336/eric-cheung/python/ch-2.py (limited to 'challenge-336/eric-cheung/python') 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)) -- cgit