aboutsummaryrefslogtreecommitdiff
path: root/challenge-168/eric-cheung/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-06-07 17:54:35 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-06-07 17:54:35 +0100
commit541cbe1b04d5e804d2cabe879317cff9ae3f5cb4 (patch)
tree1ebf2defb0e5a60b602fe4df0bc2e13fb4258333 /challenge-168/eric-cheung/python/ch-1.py
parente4ec6fd9f31c65a9a55fb48c6c1b5ea1ad3a2efa (diff)
downloadperlweeklychallenge-club-541cbe1b04d5e804d2cabe879317cff9ae3f5cb4.tar.gz
perlweeklychallenge-club-541cbe1b04d5e804d2cabe879317cff9ae3f5cb4.tar.bz2
perlweeklychallenge-club-541cbe1b04d5e804d2cabe879317cff9ae3f5cb4.zip
- Added guest contributions by Eric Cheung.
Diffstat (limited to 'challenge-168/eric-cheung/python/ch-1.py')
-rwxr-xr-xchallenge-168/eric-cheung/python/ch-1.py39
1 files changed, 39 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)