diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2022-02-08 15:12:14 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2022-02-08 15:12:14 +0100 |
| commit | acbd8f6b2a7471edbe77f9ea08ab82db66e1c304 (patch) | |
| tree | b8c15022fb8cb9e0f6fb39b634f348c9b94614c4 /challenge-151/abigail/python/ch-1.py | |
| parent | 5045026f0fe4bf7ba93d00350f8bb6bbde68f5be (diff) | |
| download | perlweeklychallenge-club-acbd8f6b2a7471edbe77f9ea08ab82db66e1c304.tar.gz perlweeklychallenge-club-acbd8f6b2a7471edbe77f9ea08ab82db66e1c304.tar.bz2 perlweeklychallenge-club-acbd8f6b2a7471edbe77f9ea08ab82db66e1c304.zip | |
Week 151: Python solutions
Diffstat (limited to 'challenge-151/abigail/python/ch-1.py')
| -rw-r--r-- | challenge-151/abigail/python/ch-1.py | 32 |
1 files changed, 32 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 |
