From c0ea724d4c27719ae8df9139748a2a9a6bf65bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Fri, 1 Dec 2023 20:27:42 +0100 Subject: [PATCH] Fix 2023 day 1. --- 2023/day1.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2023/day1.py b/2023/day1.py index 9bf9b82..a44fbd0 100644 --- a/2023/day1.py +++ b/2023/day1.py @@ -3,7 +3,7 @@ import sys lines = sys.stdin.read().split("\n") -lookups_1 = {d: int(d) for d in string.digits} +lookups_1 = {d: int(d) for d in string.digits[1:]} lookups_2 = lookups_1 | { d: i + 1 for i, d in enumerate( @@ -34,8 +34,9 @@ def find_values(lookups: dict[str, int]) -> list[int]: ) last_digit = max( lookups, - key=lambda lookup: index if (index := line.rfind(lookup)) >= 0 else 0, + key=lambda lookup: index if (index := line.rfind(lookup)) >= 0 else -1, ) + values.append(10 * lookups[first_digit] + lookups[last_digit]) return values