diff options
| author | Abigail <abigail@abigail.be> | 2021-08-20 00:15:30 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-08-20 00:15:30 +0200 |
| commit | ceeeb1bec20fca90c87aa2c00ccb30d3cb4ae60b (patch) | |
| tree | 3a0bf76e4ce852d4d1616cb4cf315a3af3b095d9 | |
| parent | d9fbe419a2a4fac19792a9f64d1ffe7cbd7f087e (diff) | |
| download | perlweeklychallenge-club-ceeeb1bec20fca90c87aa2c00ccb30d3cb4ae60b.tar.gz perlweeklychallenge-club-ceeeb1bec20fca90c87aa2c00ccb30d3cb4ae60b.tar.bz2 perlweeklychallenge-club-ceeeb1bec20fca90c87aa2c00ccb30d3cb4ae60b.zip | |
Python solution for week 126, part 1
| -rw-r--r-- | challenge-126/abigail/README.md | 3 | ||||
| -rw-r--r-- | challenge-126/abigail/python/ch-1.py | 24 |
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-126/abigail/README.md b/challenge-126/abigail/README.md index 20b6caa090..b6e47b7da1 100644 --- a/challenge-126/abigail/README.md +++ b/challenge-126/abigail/README.md @@ -29,7 +29,10 @@ There are 13 numbers between `1` and `25` that don't contain digit `1`: * [AWK](awk/ch-1.awk) * [Bash](bash/ch-1.sh) * [C](c/ch-1.c) +* [Lua](lua/ch-1.lua) +* [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) +* [Python](python/ch-1.py) ### Blog [Perl Weekly Challenge 126: Count Numbers][blog1] diff --git a/challenge-126/abigail/python/ch-1.py b/challenge-126/abigail/python/ch-1.py new file mode 100644 index 0000000000..eda639ebdb --- /dev/null +++ b/challenge-126/abigail/python/ch-1.py @@ -0,0 +1,24 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +for line in fileinput . input (): + result = 0 + seen_one = False + for digit in list (line . strip ()): + result = result * 9 + if seen_one: + result = result + 8 + elif digit == "1": + seen_one = True + elif digit != "0": + result = result + int (digit) - 1 + print (result) |
