aboutsummaryrefslogtreecommitdiff
path: root/challenge-125/abigail/python
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-08-15 21:58:39 +0100
committerGitHub <noreply@github.com>2021-08-15 21:58:39 +0100
commit84e0ff46b3f17b71d903190abd7dd68831c11b8c (patch)
tree31ab8d58f4b76ac8c6c0ed56580dc83304f3c3d2 /challenge-125/abigail/python
parent77fce3c8870cb065511df5db166f0b4d4845b26c (diff)
parent0dfc1786c2ab2282b265ba90fe18aa32dc33e3fb (diff)
downloadperlweeklychallenge-club-84e0ff46b3f17b71d903190abd7dd68831c11b8c.tar.gz
perlweeklychallenge-club-84e0ff46b3f17b71d903190abd7dd68831c11b8c.tar.bz2
perlweeklychallenge-club-84e0ff46b3f17b71d903190abd7dd68831c11b8c.zip
Merge pull request #4715 from Abigail/abigail/week-125
Abigail/week 125
Diffstat (limited to 'challenge-125/abigail/python')
-rw-r--r--challenge-125/abigail/python/ch-1.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-125/abigail/python/ch-1.py b/challenge-125/abigail/python/ch-1.py
new file mode 100644
index 0000000000..f8c07799b3
--- /dev/null
+++ b/challenge-125/abigail/python/ch-1.py
@@ -0,0 +1,41 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+import math
+
+def introot (square):
+ return math . floor (.4 + math . sqrt (square))
+
+for line in fileinput . input ():
+ n = int (line)
+ if n <= 2:
+ print (-1)
+ continue
+
+ n_sq = n * n
+ c = n + 1
+ c_sq = n_sq + 2 * n + 1
+ while 2 * c - 1 <= n_sq:
+ b_sq = c_sq - n_sq
+ b = introot (b_sq)
+
+ if b_sq == b * b:
+ print (str (n) + " " + str (b) + " " + str (c))
+
+ c_sq = c_sq + 2 * c + 1
+ c = c + 1
+
+ max_a = math . floor (n / math . sqrt (2))
+ for a in range (3, max_a + 1):
+ b_sq = n_sq - a * a
+ b = introot (b_sq)
+ if b_sq == b * b:
+ print (str (a) + " " + str (b) + " " + str (n))