diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-10-31 17:28:13 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-10-31 17:28:13 +0000 |
| commit | a3d346ab5447bac837bb2086fdaea12bd8fbe495 (patch) | |
| tree | e4149cf4ca8c50565f4b812a7606c2ca5b43e2ba /challenge-241/eric-cheung/python | |
| parent | 84b1b95ae25c98483a94026a0bc510eb774ce39c (diff) | |
| download | perlweeklychallenge-club-a3d346ab5447bac837bb2086fdaea12bd8fbe495.tar.gz perlweeklychallenge-club-a3d346ab5447bac837bb2086fdaea12bd8fbe495.tar.bz2 perlweeklychallenge-club-a3d346ab5447bac837bb2086fdaea12bd8fbe495.zip | |
- Added solutions by E. Choroba.
- Added solutions by Robbie Hatley.
- Added solutions by rcmlz.
- Added solutions by Mark Anderson.
- Added solutions by Lubos Kolouch.
- Added solutions by W. Luis Mochan.
- Added solutions by David Ferrone.
- Added solutions by Peter Campbell Smith.
- Added solutions by Kjetil Skotheim.
- Added solutions by Dave Jacoby.
- Added solutions by Niels van Dijke.
- Added solutions by Packy Anderson.
- Added solutions by Luca Ferrari.
- Added solutions by Thomas Kohler.
- Added solutions by Ali Moradi.
- Added solutions by Roger Bell_West.
Diffstat (limited to 'challenge-241/eric-cheung/python')
| -rwxr-xr-x | challenge-241/eric-cheung/python/ch-1.py | 28 | ||||
| -rwxr-xr-x | challenge-241/eric-cheung/python/ch-2.py | 40 |
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-241/eric-cheung/python/ch-1.py b/challenge-241/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..6e19580d14 --- /dev/null +++ b/challenge-241/eric-cheung/python/ch-1.py @@ -0,0 +1,28 @@ +
+from itertools import combinations
+
+def IsAriTriplet (arrInput, nDiffInput):
+ if arrInput[1] - arrInput[0] != nDiffInput:
+ return False
+ if arrInput[2] - arrInput[1] != nDiffInput:
+ return False
+ return True
+
+
+## Example 1
+## arrNum = [0, 1, 4, 6, 7, 10]
+## nDiff = 3
+
+## Example 2
+arrNum = [4, 5, 6, 7, 8, 9]
+nDiff = 2
+
+
+arrCombList = combinations(arrNum, 3)
+arrOutputList = []
+
+for arrLoop in list(arrCombList):
+ if IsAriTriplet(arrLoop, nDiff):
+ arrOutputList.append(arrOutputList)
+
+print (len(arrOutputList))
diff --git a/challenge-241/eric-cheung/python/ch-2.py b/challenge-241/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..a1eb778bf5 --- /dev/null +++ b/challenge-241/eric-cheung/python/ch-2.py @@ -0,0 +1,40 @@ +
+from math import sqrt
+
+def GetPrimeFact(nInput):
+ if nInput < 2:
+ return []
+ if nInput == 2:
+ return [2]
+
+ ## ====== ##
+ nNum = nInput
+ arrOuput = []
+ while nNum % 2 == 0:
+ arrOuput.append(2)
+ nNum = int(nNum / 2)
+ ## ====== ##
+
+ ## ====== ##
+ nDiv = 3
+ nRoot = int(sqrt(nNum))
+ while nDiv < nRoot + 1:
+ if nNum % nDiv == 0:
+ arrOuput.append(nDiv)
+ nNum = int(nNum / nDiv)
+ else:
+ nDiv = nDiv + 2
+ ## ====== ##
+
+ return arrOuput
+
+arrInput = [11, 8, 27, 4]
+
+for nRowIndx in range(0, len(arrInput) - 1):
+ for nColIndx in range(nRowIndx + 1, len(arrInput)):
+ if len(GetPrimeFact(arrInput[nRowIndx])) > len(GetPrimeFact(arrInput[nColIndx])) or len(GetPrimeFact(arrInput[nRowIndx])) == len(GetPrimeFact(arrInput[nColIndx])) and arrInput[nRowIndx] > arrInput[nColIndx]:
+ nTemp = arrInput[nRowIndx]
+ arrInput[nRowIndx] = arrInput[nColIndx]
+ arrInput[nColIndx] = nTemp
+
+print (arrInput)
|
