diff options
| author | Ryan Thompson <rjt-pl@users.noreply.github.com> | 2022-06-16 17:10:46 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-16 17:10:46 -0600 |
| commit | c92803076d8d8f9fee7bb945e0e268399e32cdd3 (patch) | |
| tree | f59a55e4a378f42fa80a5b6f13238b12088e7d4b /challenge-169/eric-cheung/python/ch-2.py | |
| parent | 40198d275c123f30a185aea4da69f2c3b9424dab (diff) | |
| parent | 7c2fa584618da574d42b1713c3c343423991c781 (diff) | |
| download | perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.tar.gz perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.tar.bz2 perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-169/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-169/eric-cheung/python/ch-2.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/challenge-169/eric-cheung/python/ch-2.py b/challenge-169/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..af7725e75b --- /dev/null +++ b/challenge-169/eric-cheung/python/ch-2.py @@ -0,0 +1,80 @@ +
+## Remarks
+## https://en.wikipedia.org/wiki/Achilles_number
+
+
+import numpy as np
+import math
+
+
+def GetUniqueCount(arrList):
+ arrObj = np.array(arrList)
+ return np.unique(arrObj, return_counts = True)
+
+
+def IsPrime(nInput):
+
+ for nDiv in range(2, int(math.sqrt(nInput)) + 1):
+ if nInput % nDiv == 0:
+ return False
+
+ return True
+
+
+def PrimeFact(nOrigInput):
+
+ nInput = nOrigInput
+ arrPrimeFact = []
+
+ if IsPrime(nInput):
+ arrPrimeFact.append(nInput)
+ return arrPrimeFact
+
+ for nDiv in range(2, nOrigInput):
+
+ while nInput % nDiv == 0 and nInput > 0:
+
+ nInput = nInput / nDiv
+ arrPrimeFact.append(nDiv)
+
+ if nInput == 0:
+ break
+
+ return arrPrimeFact
+
+
+def IsAchillesNum(nInput):
+
+ ## print (nInput)
+
+ arrPrime, arrCount = GetUniqueCount(PrimeFact(nInput))
+
+ ## print (arrPrime)
+ ## print (arrCount)
+
+ ## Check Is Powerful
+ if min(arrCount) == 1:
+ return False
+
+ ## Check Is Perfect
+ if math.gcd(*arrCount) > 1:
+ return False
+
+ return True
+
+
+## print (PrimeFact(37))
+## print (IsAchillesNum(36))
+## print (IsAchillesNum(72))
+## print (IsAchillesNum(144))
+
+
+nCount = 0
+nLoop = 2
+
+while nCount < 20:
+ if IsAchillesNum(nLoop):
+ print(nLoop)
+ nCount = nCount + 1
+
+ nLoop = nLoop + 1
|
