diff options
Diffstat (limited to 'challenge-168/eric-cheung/python')
| -rwxr-xr-x | challenge-168/eric-cheung/python/ch-1.py | 39 | ||||
| -rwxr-xr-x | challenge-168/eric-cheung/python/ch-2.py | 57 |
2 files changed, 96 insertions, 0 deletions
diff --git a/challenge-168/eric-cheung/python/ch-1.py b/challenge-168/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..df5ae80e8e --- /dev/null +++ b/challenge-168/eric-cheung/python/ch-1.py @@ -0,0 +1,39 @@ +
+## Remarks
+## https://en.wikipedia.org/wiki/Perrin_number
+
+import math
+
+def IsPrime(nInput):
+
+ for nDiv in range(2, int(math.sqrt(nInput)) + 1):
+ if nInput % nDiv == 0:
+ return False
+
+ return True
+
+arrPerrinPrime = []
+arrPerrinNum = []
+
+arrPerrinNum.append(3)
+arrPerrinNum.append(0)
+arrPerrinNum.append(2)
+
+arrPerrinPrime.append(2)
+arrPerrinPrime.append(3)
+
+while len(arrPerrinPrime) < 13:
+ nNuNum = arrPerrinNum[-2] + arrPerrinNum[-3]
+ arrPerrinNum.append(nNuNum)
+
+ if not IsPrime(nNuNum):
+ continue
+
+ nCount = arrPerrinPrime.count(nNuNum)
+
+ if nCount > 0:
+ continue
+
+ arrPerrinPrime.append(nNuNum)
+
+print (arrPerrinPrime)
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))
+
|
