diff options
| author | 冯昶 <seaker@qq.com> | 2021-05-24 15:49:34 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-05-24 15:49:34 +0800 |
| commit | b876dd5b111bf1c267b2fb58cd64e6b655128e5c (patch) | |
| tree | 95d82b58ea802af7a3cb3d20c72af0a7be502954 /challenge-113/abigail/python | |
| parent | d848d3cf55a41587d2e8809838ffec2a84d4491d (diff) | |
| parent | c61ba475fd263546925b47f264825a44477622e0 (diff) | |
| download | perlweeklychallenge-club-b876dd5b111bf1c267b2fb58cd64e6b655128e5c.tar.gz perlweeklychallenge-club-b876dd5b111bf1c267b2fb58cd64e6b655128e5c.tar.bz2 perlweeklychallenge-club-b876dd5b111bf1c267b2fb58cd64e6b655128e5c.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-113/abigail/python')
| -rw-r--r-- | challenge-113/abigail/python/ch-1.py | 40 | ||||
| -rw-r--r-- | challenge-113/abigail/python/ch-2.py | 16 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-113/abigail/python/ch-1.py b/challenge-113/abigail/python/ch-1.py new file mode 100644 index 0000000000..ebb8821ddc --- /dev/null +++ b/challenge-113/abigail/python/ch-1.py @@ -0,0 +1,40 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +# +# For a description of the algorithm, and the proof why this is correct: +# https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-113-1.html +# + +import fileinput + +gcds = [0, 1, 2, 1, 2, 5, 2, 1, 2, 1] + +for line in fileinput . input (): + (N, D) = line . split (); + N = int (N) + D = int (D) + if D == 0: + print (1 if N >= 100 or N % 10 == 0 else 0) + continue + + if N >= D * 10: + print (1) + continue + + done = False + for i in range (0, D // gcds [D]): + T = N - 10 * i - D + if T >= 0 and T % D == 0: + print (1) + done = True + break + if not done: + print (0) diff --git a/challenge-113/abigail/python/ch-2.py b/challenge-113/abigail/python/ch-2.py new file mode 100644 index 0000000000..73b6b9bc8b --- /dev/null +++ b/challenge-113/abigail/python/ch-2.py @@ -0,0 +1,16 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +for line in fileinput . input (): + numbers = list (map (lambda _: int (_), line . split ())) + total = sum (numbers) + print (' ' . join (map (lambda _: str (total - _), numbers))) |
