From 541cbe1b04d5e804d2cabe879317cff9ae3f5cb4 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 7 Jun 2022 17:54:35 +0100 Subject: - Added guest contributions by Eric Cheung. --- challenge-168/eric-cheung/python/ch-2.py | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 challenge-168/eric-cheung/python/ch-2.py (limited to 'challenge-168/eric-cheung/python/ch-2.py') 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)) + -- cgit