day 01: some cleanup, catch lines without any digits
This commit is contained in:
parent
e01dfeab9e
commit
ef2459f0c9
2 changed files with 3 additions and 3 deletions
|
|
@ -22,7 +22,7 @@ def get_lines(filename: str) -> list:
|
|||
|
||||
def get_cal_val(line: str) -> int:
|
||||
found_first = False
|
||||
first = ""
|
||||
first = "0"
|
||||
last = ""
|
||||
for test_char in line:
|
||||
if test_char.isdigit():
|
||||
|
|
@ -30,9 +30,8 @@ def get_cal_val(line: str) -> int:
|
|||
last = test_char
|
||||
else:
|
||||
first = test_char
|
||||
last = first
|
||||
found_first = True
|
||||
if last == "":
|
||||
last = first
|
||||
return int(first + last)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class TestThing(unittest.TestCase):
|
|||
self.assertEqual(program.get_cal_val("th95"), 95)
|
||||
self.assertEqual(program.get_cal_val("g2"), 22)
|
||||
self.assertEqual(program.get_cal_val("2"), 22)
|
||||
self.assertEqual(program.get_cal_val("wjezrg"), 0)
|
||||
|
||||
def testReplaceDigitStrings(self):
|
||||
self.assertEqual(program.replace_digit_strings("one"), "o1e")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue