diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-01-12 15:59:26 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-01-12 15:59:26 +0000 |
| commit | dd99d53e09a332c4ff5153b8bb54c9506a03860d (patch) | |
| tree | e65264cbef15fbcd3e15dd12da74cc5084e507cb /challenge-147/eric-cheung/python | |
| parent | 94cdbab3f1198c78a3dcedb9ada1a8596114cfcb (diff) | |
| parent | d995c005f623c0f80f4cdfbf2247856c146fd7e3 (diff) | |
| download | perlweeklychallenge-club-dd99d53e09a332c4ff5153b8bb54c9506a03860d.tar.gz perlweeklychallenge-club-dd99d53e09a332c4ff5153b8bb54c9506a03860d.tar.bz2 perlweeklychallenge-club-dd99d53e09a332c4ff5153b8bb54c9506a03860d.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-147/eric-cheung/python')
| -rwxr-xr-x | challenge-147/eric-cheung/python/ch-2.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-147/eric-cheung/python/ch-2.py b/challenge-147/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..6a716b2ddd --- /dev/null +++ b/challenge-147/eric-cheung/python/ch-2.py @@ -0,0 +1,45 @@ +## Remarks
+## https://www.mathblog.dk/project-euler-44-smallest-pair-pentagonal-numbers/
+## https://radiusofcircle.blogspot.com/2016/06/problem-44-project-euler-solution-with-python.html
+## http://radiusofcircle.blogspot.com
+
+## Time Module for Calculating Execution Time
+import time
+
+## Time At The Start of Program Execution
+dStartTime = time.time()
+
+def is_pentagonal(nInput):
+ ## Function To Check If The Number is Pentagonal Number or Not
+ if (1 + (24 * nInput + 1) ** 0.5) % 6 == 0:
+ return True
+ return False
+
+## Flag To Check If The Number Is Found Or Not
+bFlag = True
+
+# While Loop Iterator
+nLoop = 1
+
+# While Loop
+while bFlag:
+ nNum_01 = nLoop * (3 * nLoop - 1) / 2
+ for nSubLoop in range(1, nLoop):
+ nNum_02 = nSubLoop * (3 * nSubLoop - 1) / 2
+ if is_pentagonal(nNum_01 + nNum_02) and is_pentagonal(nNum_01 - nNum_02):
+ print ("nLoop = " + str(nLoop) + ", nSubLoop = " + str(nSubLoop))
+ bFlag = False
+ break
+ nLoop = nLoop + 1
+
+# Time At The End of Program Execution
+dEndTime = time.time()
+
+# Printing The Total Time For Execution
+print ("Time Needed: " + str(dEndTime - dStartTime))
+
+
+## Result
+## nLoop = 2167, nSubLoop = 1020
+## Time Needed: 1.1174473762512207
+
|
