diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-01-23 19:46:16 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-23 19:46:16 +0000 |
| commit | a3ef8061e8b28fd26ff9aa4ee3fc9f39ceb55dc1 (patch) | |
| tree | e65b7cbfb63e9b6bbcdb6b173bfec9215e70151d /challenge-148/abigail/python | |
| parent | 919e4948116f4a0f1c1c2580b856dd221568dcb0 (diff) | |
| parent | 895121c6f016a222efcfe4a99df34b8138fb2055 (diff) | |
| download | perlweeklychallenge-club-a3ef8061e8b28fd26ff9aa4ee3fc9f39ceb55dc1.tar.gz perlweeklychallenge-club-a3ef8061e8b28fd26ff9aa4ee3fc9f39ceb55dc1.tar.bz2 perlweeklychallenge-club-a3ef8061e8b28fd26ff9aa4ee3fc9f39ceb55dc1.zip | |
Merge pull request #5552 from Abigail/abigail/week-148
Abigail/week 148
Diffstat (limited to 'challenge-148/abigail/python')
| -rw-r--r-- | challenge-148/abigail/python/ch-1.py | 19 | ||||
| -rw-r--r-- | challenge-148/abigail/python/ch-2.py | 80 |
2 files changed, 99 insertions, 0 deletions
diff --git a/challenge-148/abigail/python/ch-1.py b/challenge-148/abigail/python/ch-1.py new file mode 100644 index 0000000000..f0d3591271 --- /dev/null +++ b/challenge-148/abigail/python/ch-1.py @@ -0,0 +1,19 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-148 +# + +# +# Run as: python ch-1.py +# + +import sys, re + +for i in range (101): + if not (i == 0 or re . search (r'[1789]', str (i)) + or re . search (r'^2.', str (i)) + or re . search (r'[35]$', str (i))): + sys . stdout . write (str (i) + " ") + +sys . stdout . write ("\n") diff --git a/challenge-148/abigail/python/ch-2.py b/challenge-148/abigail/python/ch-2.py new file mode 100644 index 0000000000..e867dbb0f8 --- /dev/null +++ b/challenge-148/abigail/python/ch-2.py @@ -0,0 +1,80 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-148 +# + +# +# Run as: python ch-2.py +# + +import math + +COUNT = 5 +A = 0 +B = 1 +C = 2 +SUM = 3 +out = [] +for i in range (COUNT): + out . append ([999999, 999999, 999999, 999999 * 3]) + +max_index = 0 +k = 0 + + +while 3 * k + 2 < out [max_index] [SUM]: + a = 3 * k + 2 + f1 = k + 1 + f2 = 8 * k + 5 + + d1 = [] + for i in range (1, f1 + 1): + if i * i > f1: + break + if f1 % i == 0: + d1 . append (i) + if i != f1 // i: + d1 . append (f1 // i) + + + d2 = [] + for i in range (1, f2 + 1): + if i * i > f2: + break + if f2 % i == 0: + s1 = math . isqrt (i) + s2 = math . isqrt (f2 // i) + if s1 * s1 == i: + d2 . append (s1) + if s2 * s2 == f2 // i and s1 != s2: + d2 . append (s2) + + for d1v in d1: + for d2v in d2: + b = d1v * d2v + c = f1 * f1 * f2 // (b * b) + + if a + b + c < out [max_index] [SUM]: + seen = False + for i in range (COUNT): + if out [i] [A] == a and out [i] [B] == b: + seen = true + break + if seen: + break + + out [max_index] = [a, b, c, a + b + c] + + max_index = 0 + max_sum = out [max_index] [SUM] + for i in range (1, COUNT): + if max_sum < out [i] [SUM]: + max_sum = out [i] [SUM] + max_index = i + + k = k + 1 + + +for i in range (COUNT): + print (out [i] [A], out [i] [B], out [i] [C]) |
