aboutsummaryrefslogtreecommitdiff
path: root/challenge-169/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-06-15 18:59:58 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-06-15 18:59:58 +0100
commitd71fa6f60a0797100b3e151ea7f93d8f0b428423 (patch)
tree6d6e28cd0bbb8d28677ef35c26302d7a1a19c704 /challenge-169/eric-cheung/python
parent3f88ca21a50ab1051b5d70b65e93d11b399fa4af (diff)
downloadperlweeklychallenge-club-d71fa6f60a0797100b3e151ea7f93d8f0b428423.tar.gz
perlweeklychallenge-club-d71fa6f60a0797100b3e151ea7f93d8f0b428423.tar.bz2
perlweeklychallenge-club-d71fa6f60a0797100b3e151ea7f93d8f0b428423.zip
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-169/eric-cheung/python')
-rwxr-xr-xchallenge-169/eric-cheung/python/ch-1.py46
-rwxr-xr-xchallenge-169/eric-cheung/python/ch-2.py80
2 files changed, 126 insertions, 0 deletions
diff --git a/challenge-169/eric-cheung/python/ch-1.py b/challenge-169/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..aa1dde99b9
--- /dev/null
+++ b/challenge-169/eric-cheung/python/ch-1.py
@@ -0,0 +1,46 @@
+
+## Remarks
+
+import math
+
+def PrimeFact(nInput):
+
+ for nDiv in range(2, int(math.sqrt(nInput)) + 1):
+ if nInput % nDiv == 0:
+ return nDiv
+
+ return 0
+
+
+def IsBrillNum(nInput):
+
+ nFact = PrimeFact(nInput)
+
+ if nFact == 0:
+ return False
+
+ nFact_2 = int(nInput / nFact)
+
+ nNum = PrimeFact(nFact_2)
+
+ if nNum > 0:
+ return False
+
+ if len(str(nFact)) == len(str(nFact_2)):
+ return True
+
+ return False
+
+
+## nOrigInputNum = 5
+## print (IsBrillNum(nOrigInputNum))
+
+nCount = 0
+nLoop = 4
+
+while nCount < 20:
+ if IsBrillNum(nLoop):
+ print(nLoop)
+ nCount = nCount + 1
+
+ nLoop = nLoop + 1
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