advent_of_code/2023/1/1.py
2023-12-02 13:53:24 +01:00

21 lines
553 B
Python

#!/usr/bin/env python
# 2023 - Advent Of Code 1
# file = 'input_example.txt'
file = 'input.txt'
with open(file, encoding="utf-8") as f:
accum = 0
for line in f.readlines():
first_num = -1
for c in line:
if '0' <= c <= '9':
if first_num == -1:
first_num = c
last_num = c
line_num = first_num + last_num
# print(f"first: {first_num}, last: {last_num}")
# print(f"line_num: {line_num}")
accum += int(line_num)
print(f"sum: {accum}")