diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2022-06-11 18:03:19 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2022-06-11 18:03:19 -0400 |
| commit | 0bbeea39910584ad596b393dae30111d7ecfad5f (patch) | |
| tree | 5320b1593a3a24d970be8b8cf9629dc17e9d66e2 /challenge-168/eric-cheung/python/ch-2.py | |
| parent | f95f9de8bebf4967125de3a10999cbe524f9f1a3 (diff) | |
| parent | bd3744516843c761ecb3448e1779f0828e3917a0 (diff) | |
| download | perlweeklychallenge-club-0bbeea39910584ad596b393dae30111d7ecfad5f.tar.gz perlweeklychallenge-club-0bbeea39910584ad596b393dae30111d7ecfad5f.tar.bz2 perlweeklychallenge-club-0bbeea39910584ad596b393dae30111d7ecfad5f.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-168/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-168/eric-cheung/python/ch-2.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/challenge-168/eric-cheung/python/ch-2.py b/challenge-168/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..4bcd6f1e3a --- /dev/null +++ b/challenge-168/eric-cheung/python/ch-2.py @@ -0,0 +1,57 @@ +
+## Remarks
+## https://en.wikipedia.org/wiki/Home_prime
+
+import math
+
+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 = []
+
+ 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 ConcatArray(arrInput):
+
+ strResult = ""
+
+ for arrElem in arrInput:
+ strResult = strResult + str(arrElem)
+
+ return int(strResult)
+
+
+## print (PrimeFact(511))
+## print (ConcatArray(PrimeFact(511)))
+## print (ConcatArray(PrimeFact(8)))
+
+
+nOrigInputNum = 10
+
+nInputNum = nOrigInputNum
+
+while not IsPrime(nInputNum):
+ nInputNum = ConcatArray(PrimeFact(nInputNum))
+
+print ("HP(" + str(nOrigInputNum) + ") = " + str(nInputNum))
+
|
