advent-of-code/2023/d01/ex1/ex1.py

21 lines
378 B
Python
Raw Permalink Normal View History

2023-12-01 13:13:28 +01:00
#!/usr/bin/env python
import sys
def solve(input: list[str]) -> int:
def value(line: str) -> int:
digits = [int(c) for c in line if c.isdigit()]
return digits[0] * 10 + digits[-1]
return sum(value(line) for line in input)
def main() -> None:
input = sys.stdin.read().splitlines()
print(solve(input))
if __name__ == "__main__":
main()