diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-12-08 18:18:52 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-12-08 18:18:52 +0000 |
| commit | b18ca39f9bb4cf8d5015c242b3ae3f8359c2f4af (patch) | |
| tree | 43f6b29accd85e77f3fc3c7d8ab963f1a4fd1169 /challenge-246/eric-cheung/python/ch-2.py | |
| parent | d61c1a7e514cf0dfb978348c91ca6a662a61785b (diff) | |
| download | perlweeklychallenge-club-b18ca39f9bb4cf8d5015c242b3ae3f8359c2f4af.tar.gz perlweeklychallenge-club-b18ca39f9bb4cf8d5015c242b3ae3f8359c2f4af.tar.bz2 perlweeklychallenge-club-b18ca39f9bb4cf8d5015c242b3ae3f8359c2f4af.zip | |
- Added solutions by Jorg Sommrey.
- Added solutions by W. Luis Mochan.
- Added solutions by Eric Cheung.
Diffstat (limited to 'challenge-246/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-246/eric-cheung/python/ch-2.py | 23 |
1 files changed, 22 insertions, 1 deletions
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:
|
