Fix 2023 day 1.

This commit is contained in:
Mikaël Capelle 2023-12-01 20:27:42 +01:00
parent 57c15270dc
commit c0ea724d4c

View File

@ -3,7 +3,7 @@ import sys
lines = sys.stdin.read().split("\n") 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 | { lookups_2 = lookups_1 | {
d: i + 1 d: i + 1
for i, d in enumerate( for i, d in enumerate(
@ -34,8 +34,9 @@ def find_values(lookups: dict[str, int]) -> list[int]:
) )
last_digit = max( last_digit = max(
lookups, 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]) values.append(10 * lookups[first_digit] + lookups[last_digit])
return values return values