diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-11-13 10:15:17 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-11-13 10:15:17 +0800 |
| commit | 41f99d3c168e8def8c2a799c592282acf0d275a8 (patch) | |
| tree | e862f32c73ecc3b39546d8f2e40268097bdc84eb /challenge-241/eric-cheung/python/ch-2.py | |
| parent | 9831ad5b94643aec63e30e720b83dff7a5eac18b (diff) | |
| parent | f4d46d9aa21b95dbb99eec92f338d157273fbbdb (diff) | |
| download | perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.tar.gz perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.tar.bz2 perlweeklychallenge-club-41f99d3c168e8def8c2a799c592282acf0d275a8.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-241/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-241/eric-cheung/python/ch-2.py | 40 |
1 files changed, 40 insertions, 0 deletions
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)
|
