aboutsummaryrefslogtreecommitdiff
path: root/challenge-125/abigail/python
diff options
context:
space:
mode:
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))