Solve day 9 and fix horrible bug in lib.

My integer parser did not consider negative values. I have fixed that
in the 2022 repository, but not here. That's pretty annoying.
This commit is contained in:
2023-12-09 11:48:39 -05:00
parent 203f921c9f
commit 9485fbae1d
3 changed files with 57 additions and 3 deletions

4
lib.py
View File

@@ -34,13 +34,13 @@ def lcm(numbers: list[int]) -> int:
def str_to_single_int(line: str) -> int:
line = line.replace(" ", "")
r = re.compile(r"\d+")
r = re.compile(r"-?\d+")
for m in r.findall(line):
return int(m)
raise Exception("No single digit sequence in '{line}'")
def str_to_int_list(line: str) -> list[int]:
r = re.compile(r"\d+")
r = re.compile(r"-?\d+")
return list(map(int, r.findall(line)))
def str_to_lines_no_empty(text: str) -> list[str]: