diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-02-08 20:03:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-08 20:03:07 +0000 |
| commit | 9e8211950a93c9370824c4cd25092d2c72cef692 (patch) | |
| tree | b02229e447f129e60744b12f9872796e22e41c40 /challenge-151/abigail/python | |
| parent | bdaaa49f20ca56057a3a478a383f0af2253f6f6b (diff) | |
| parent | a09d0dd70c22dc386c4280cfae04158098dcc924 (diff) | |
| download | perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.tar.gz perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.tar.bz2 perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.zip | |
Merge pull request #5629 from Abigail/abigail/week-151
Abigail/week 151
Diffstat (limited to 'challenge-151/abigail/python')
| -rw-r--r-- | challenge-151/abigail/python/ch-1.py | 32 | ||||
| -rw-r--r-- | challenge-151/abigail/python/ch-2.py | 19 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-151/abigail/python/ch-1.py b/challenge-151/abigail/python/ch-1.py new file mode 100644 index 0000000000..12dec88d86 --- /dev/null +++ b/challenge-151/abigail/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151 +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +for line in fileinput . input (): + tree = list (map (lambda row: row . strip () . split (), + line . strip () . split ("|"))) + for d in range (len (tree)): + if (d == len (tree) - 1): + print (d + 1) + break + done = False + for i in range (len (tree [d])): + if tree [d] [i] != "*": + ch1 = 2 * i + ch2 = 2 * i + 1 + if ch1 >= len (tree [d + 1]) or ( + (tree [d + 1] [ch1] == "*" and ( + ch2 >= len (tree [d + 1]) or tree [d + 1] [ch2] == "*"))): + print (d + 1) + done = True + break + if done: + break diff --git a/challenge-151/abigail/python/ch-2.py b/challenge-151/abigail/python/ch-2.py new file mode 100644 index 0000000000..52522eff0b --- /dev/null +++ b/challenge-151/abigail/python/ch-2.py @@ -0,0 +1,19 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-151 +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +for line in fileinput . input (): + h = list (map (lambda x: int (x), line . strip () . split ())) + h . append (0) + h . append (0) + for i in range (len (h) - 3, 1, -1): + h [i] = max (h [i] + h [i + 2], h [i + 1]) + print (h [0] + h [2]) |
