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:
|
def get_cal_val(line: str) -> int:
|
||||||
found_first = False
|
found_first = False
|
||||||
first = ""
|
first = "0"
|
||||||
last = ""
|
last = ""
|
||||||
for test_char in line:
|
for test_char in line:
|
||||||
if test_char.isdigit():
|
if test_char.isdigit():
|
||||||
|
|
@ -30,9 +30,8 @@ def get_cal_val(line: str) -> int:
|
||||||
last = test_char
|
last = test_char
|
||||||
else:
|
else:
|
||||||
first = test_char
|
first = test_char
|
||||||
found_first = True
|
|
||||||
if last == "":
|
|
||||||
last = first
|
last = first
|
||||||
|
found_first = True
|
||||||
return int(first + last)
|
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("th95"), 95)
|
||||||
self.assertEqual(program.get_cal_val("g2"), 22)
|
self.assertEqual(program.get_cal_val("g2"), 22)
|
||||||
self.assertEqual(program.get_cal_val("2"), 22)
|
self.assertEqual(program.get_cal_val("2"), 22)
|
||||||
|
self.assertEqual(program.get_cal_val("wjezrg"), 0)
|
||||||
|
|
||||||
def testReplaceDigitStrings(self):
|
def testReplaceDigitStrings(self):
|
||||||
self.assertEqual(program.replace_digit_strings("one"), "o1e")
|
self.assertEqual(program.replace_digit_strings("one"), "o1e")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue