diff options
| author | Walt Mankowski <waltman@pobox.com> | 2020-10-13 21:18:20 -0400 |
|---|---|---|
| committer | Walt Mankowski <waltman@pobox.com> | 2020-10-13 21:18:20 -0400 |
| commit | 2d0c4c1678aa2caa7f0c42e90708ffa019dfc988 (patch) | |
| tree | dd2fbedffc563d7edabf3a2bc7f454c37ce31577 /challenge-082 | |
| parent | fa86269bd5c1a37f0f28d528ecb278b7899b88f1 (diff) | |
| download | perlweeklychallenge-club-2d0c4c1678aa2caa7f0c42e90708ffa019dfc988.tar.gz perlweeklychallenge-club-2d0c4c1678aa2caa7f0c42e90708ffa019dfc988.tar.bz2 perlweeklychallenge-club-2d0c4c1678aa2caa7f0c42e90708ffa019dfc988.zip | |
replaced bounds checking with try clauses
Diffstat (limited to 'challenge-082')
| -rw-r--r-- | challenge-082/walt-mankowski/python/ch-2.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/challenge-082/walt-mankowski/python/ch-2.py b/challenge-082/walt-mankowski/python/ch-2.py index 662f0816d6..c9ef4de6f2 100644 --- a/challenge-082/walt-mankowski/python/ch-2.py +++ b/challenge-082/walt-mankowski/python/ch-2.py @@ -3,17 +3,21 @@ from sys import argv def is_interleave(a, b, c): if a == '' and b == '' and c == '': return 1 - elif c == '': - return 0 found = False - if len(a) > 0 and a[0] == c[0]: - found = True - return is_interleave(a[1:], b, c[1:]) + try: + if a[0] == c[0]: + found = True + return is_interleave(a[1:], b, c[1:]) + except IndexError: + pass - if len(b) > 0 and b[0] == c[0]: - found = True - return is_interleave(a, b[1:], c[1:]) + try: + if b[0] == c[0]: + found = True + return is_interleave(a, b[1:], c[1:]) + except IndexError: + pass if not found: return 0 |
