Fix 2023 day 1.

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

View File

@ -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