aboutsummaryrefslogtreecommitdiff
path: root/challenge-147/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
authorRoger Bell_West <Firedrake@users.noreply.github.com>2022-01-10 10:58:14 +0000
committerRoger Bell_West <Firedrake@users.noreply.github.com>2022-01-10 10:58:14 +0000
commit89b75091efcc8ab7ec62564a9dbe319cb0552eba (patch)
treea07d964290c1927412d827375c28126975744653 /challenge-147/roger-bell-west/python/ch-2.py
parente9411bdc7658179af3f23d3ada7970323547a7d7 (diff)
downloadperlweeklychallenge-club-89b75091efcc8ab7ec62564a9dbe319cb0552eba.tar.gz
perlweeklychallenge-club-89b75091efcc8ab7ec62564a9dbe319cb0552eba.tar.bz2
perlweeklychallenge-club-89b75091efcc8ab7ec62564a9dbe319cb0552eba.zip
Solutions for challenge #147
Diffstat (limited to 'challenge-147/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-147/roger-bell-west/python/ch-2.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-147/roger-bell-west/python/ch-2.py b/challenge-147/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..83f5c48bba
--- /dev/null
+++ b/challenge-147/roger-bell-west/python/ch-2.py
@@ -0,0 +1,41 @@
+#! /usr/bin/python3
+
+def pentagon(n):
+ return int(n*(3*n-1)/2)
+
+def pentpair():
+ fpent=[0]
+ rpent=dict()
+ mx=0
+ a=1
+ while 1:
+ while mx < a:
+ mx += 1
+ fpent.append(pentagon(mx))
+ rpent[fpent[mx]]=mx
+ for b in range(1,a):
+ d=fpent[a]-fpent[b]
+ if d < fpent[b]:
+ break
+ if d in rpent:
+ s=fpent[a]+fpent[b]
+ while s > fpent[mx]:
+ mx += 1
+ fpent.append(pentagon(mx))
+ rpent[fpent[mx]]=mx
+ if s in rpent:
+ print("P({:d}) + P({:d}) = {:d} + {:d} = {:d} = P({:d})".format(
+ a, b,
+ fpent[a], fpent[b],
+ s,
+ rpent[s]))
+ print("P({:d}) - P({:d}) = {:d} - {:d} = {:d} = P({:d})".format(
+ a, b,
+ fpent[a], fpent[b],
+ d,
+ rpent[d]))
+ quit()
+ a += 1
+
+
+pentpair()