aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWalt Mankowski <waltman@pobox.com>2020-10-13 21:18:20 -0400
committerWalt Mankowski <waltman@pobox.com>2020-10-13 21:18:20 -0400
commit2d0c4c1678aa2caa7f0c42e90708ffa019dfc988 (patch)
treedd2fbedffc563d7edabf3a2bc7f454c37ce31577
parentfa86269bd5c1a37f0f28d528ecb278b7899b88f1 (diff)
downloadperlweeklychallenge-club-2d0c4c1678aa2caa7f0c42e90708ffa019dfc988.tar.gz
perlweeklychallenge-club-2d0c4c1678aa2caa7f0c42e90708ffa019dfc988.tar.bz2
perlweeklychallenge-club-2d0c4c1678aa2caa7f0c42e90708ffa019dfc988.zip
replaced bounds checking with try clauses
-rw-r--r--challenge-082/walt-mankowski/python/ch-2.py20
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