diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2021-08-16 15:30:40 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2021-08-16 15:30:40 -0400 |
| commit | 637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3 (patch) | |
| tree | 9809af6d10a767e998f569b80cabfdeb979ece95 /challenge-125/abigail/python | |
| parent | 989dcde471a30935b8e51c557b971496963caffc (diff) | |
| parent | d9bbad705412903ffd55fb8c07bedcaeae734f85 (diff) | |
| download | perlweeklychallenge-club-637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3.tar.gz perlweeklychallenge-club-637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3.tar.bz2 perlweeklychallenge-club-637f7bbeceeaf4a26e1e6ecba8c6fcb308790bb3.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-125/abigail/python')
| -rw-r--r-- | challenge-125/abigail/python/ch-1.py | 41 |
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)) |
