diff options
| author | Abigail <abigail@abigail.be> | 2021-05-20 15:18:52 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-05-20 15:18:52 +0200 |
| commit | 82d812d593954b31a8187c65277e29363225dd55 (patch) | |
| tree | f5def520600ae8a645a1deb02cd380ab6c70531d | |
| parent | 2eedf165fbeb5289fea6c43fbe55b47a0d1ec8f8 (diff) | |
| download | perlweeklychallenge-club-82d812d593954b31a8187c65277e29363225dd55.tar.gz perlweeklychallenge-club-82d812d593954b31a8187c65277e29363225dd55.tar.bz2 perlweeklychallenge-club-82d812d593954b31a8187c65277e29363225dd55.zip | |
Python solutions for week 113
| -rw-r--r-- | challenge-113/abigail/README.md | 2 | ||||
| -rw-r--r-- | challenge-113/abigail/python/ch-1.py | 31 | ||||
| -rw-r--r-- | challenge-113/abigail/python/ch-2.py | 16 |
3 files changed, 49 insertions, 0 deletions
diff --git a/challenge-113/abigail/README.md b/challenge-113/abigail/README.md index 34146af125..85ced087a5 100644 --- a/challenge-113/abigail/README.md +++ b/challenge-113/abigail/README.md @@ -24,6 +24,7 @@ Output: 1 * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) +* [Python](python/ch-1.py) ### Blog @@ -64,5 +65,6 @@ Output: 1 * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) +* [Python](python/ch-2.py) ### Blog diff --git a/challenge-113/abigail/python/ch-1.py b/challenge-113/abigail/python/ch-1.py new file mode 100644 index 0000000000..7bf1b0db11 --- /dev/null +++ b/challenge-113/abigail/python/ch-1.py @@ -0,0 +1,31 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +tens = [0, 0, 1, 2, 1, 0, 2, 6, 3, 8] + +for line in fileinput . input (): + (N, D) = line . split (); + N = int (N) + D = int (D) + D10 = 100 if D == 0 else 10 * D + if N >= D10 or (D == 0 and N % 10 == 0) or (D > 0 and N % D == 0): + print (1) + continue + done = False + for i in range (1, tens [D] + 1): + 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))) |
