advent_of_code/2023/1/1.py

22 lines
553 B
Python
Raw Permalink Normal View History

2023-12-01 13:57:44 +01:00
#!/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}")