From ef2459f0c91eba9b2b6917278a63983a94c53061 Mon Sep 17 00:00:00 2001 From: Heiko Ludwig Date: Fri, 1 Dec 2023 22:31:14 +0100 Subject: [PATCH] day 01: some cleanup, catch lines without any digits --- day_01/program.py | 5 ++--- day_01/test_program.py | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/day_01/program.py b/day_01/program.py index 1d888a4..2635cac 100755 --- a/day_01/program.py +++ b/day_01/program.py @@ -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) diff --git a/day_01/test_program.py b/day_01/test_program.py index c62732a..bd39a1a 100755 --- a/day_01/test_program.py +++ b/day_01/test_program.py @@ -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")