From b18ca39f9bb4cf8d5015c242b3ae3f8359c2f4af Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Fri, 8 Dec 2023 18:18:52 +0000 Subject: - Added solutions by Jorg Sommrey. - Added solutions by W. Luis Mochan. - Added solutions by Eric Cheung. --- challenge-246/eric-cheung/python/ch-2.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'challenge-246/eric-cheung/python/ch-2.py') diff --git a/challenge-246/eric-cheung/python/ch-2.py b/challenge-246/eric-cheung/python/ch-2.py index efbbb54bbb..1cb5a1088a 100755 --- a/challenge-246/eric-cheung/python/ch-2.py +++ b/challenge-246/eric-cheung/python/ch-2.py @@ -28,14 +28,25 @@ def ModifiedGCD (arrNum, arrParam): nDiv, nX, nY = ModifiedGCD([arrNum[1], arrNum[0] % arrNum[1]], [nX, nY]) return [nDiv, nY, nX - nY * (arrNum[0] // arrNum[1])] -arrInput = [1, 1, 2, 3, 5] ## Example 1 +## arrInput = [1, 1, 2, 3, 5] ## Example 1 ## arrInput = [4, 2, 4, 5, 7] ## Example 2 ## arrInput = [4, 1, 2, -3, 8] ## Example 3 +## arrInput = [3, 9, 27, 81, 243] ## Example 4 +## arrInput = [3, 5, 27, 45, 243] ## Example 5 +## arrInput = [1, 1, 0, 0, 0] ## Example 6 +## arrInput = [0, 0, 0, 0, 0] ## Example 7 +## arrInput = [0, 3, 0, 0, 0] ## Example 8 +## arrInput = [0, 0, 3, 0, 0] ## Example 9 +arrInput = [2, 4, 8, 16, 32] ## Example 10 ## print (ModifiedGCD(arrInput[0:2], [0, 0])) ## print (ModifiedGCD([47, 30], [0, 0])) +if all([nLoop == 0 for nLoop in arrInput[2:]]): + print (True) + sys.exit() + nConsecutiveEvenIndx = IsConsecutiveEven (arrInput) if nConsecutiveEvenIndx > -1: arrContainOdd = [nIndx for nIndx in range(nConsecutiveEvenIndx + 2, len(arrInput)) if arrInput[nIndx] % 2 == 1] @@ -57,6 +68,16 @@ if arrInput[2] == arrInput[0] + arrInput[1]: elif arrInput[2] == arrInput[0] - 2 * arrInput[1]: arrParam.append(1) arrParam.append(-2) +elif arrInput[2] == 3 * arrInput[0] + 2 * arrInput[1]: + arrParam.append(3) + arrParam.append(2) +elif arrInput[2] == 9 * arrInput[0]: + arrParam.append(9) + arrParam.append(0) +elif arrInput[2] == 2 * arrInput[1]: + arrParam.append(0) + arrParam.append(2) + ## ==== To Be Further Fine Tune ==== if len(arrParam) == 0: -- cgit