Fix 2023 day 1.
This commit is contained in:
parent
e991cd8b04
commit
d51fed283c
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user