From 9fc9a8a98be3336fb1bd9fb909c68af45186744e Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 11 Aug 2021 00:33:29 +0200 Subject: Solutions in 6 languages for week 125, part 1 --- challenge-125/abigail/python/ch-1.py | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 challenge-125/abigail/python/ch-1.py (limited to 'challenge-125/abigail/python') 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)) -- cgit