diff options
| author | Abigail <abigail@abigail.be> | 2021-07-01 21:59:35 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-07-01 21:59:35 +0200 |
| commit | 0fadd390f0c5b8b1421c9acb8467db4cf199d819 (patch) | |
| tree | 085d812580b4d42b9be2e23eb63420dfa6473b19 | |
| parent | 2ab88a15e2e63d52dd5c90a558d673774fe3bdf5 (diff) | |
| download | perlweeklychallenge-club-0fadd390f0c5b8b1421c9acb8467db4cf199d819.tar.gz perlweeklychallenge-club-0fadd390f0c5b8b1421c9acb8467db4cf199d819.tar.bz2 perlweeklychallenge-club-0fadd390f0c5b8b1421c9acb8467db4cf199d819.zip | |
Python solution for week 119, part 2
| -rw-r--r-- | challenge-119/abigail/python/ch-2.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-119/abigail/python/ch-2.py b/challenge-119/abigail/python/ch-2.py new file mode 100644 index 0000000000..a8d72eb708 --- /dev/null +++ b/challenge-119/abigail/python/ch-2.py @@ -0,0 +1,25 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import re +import fileinput + +def next_num (prev_num): + match = re . match ('^(.*)([012])(3*)$', "0" + prev_num) + return (re . sub ('^0', '', \ + re . sub ('11', '12', match . group (1) + \ + str (int (match . group (2)) + 1) + \ + re . sub ('3', '1', match . group (3))))) + +for num in fileinput . input (): + number = "0" + for _ in range (int (num)): + number = next_num (number) + print (number) |
