AdventOfCode2023/day1-1.py

24 lines
542 B
Python
Raw Normal View History

2023-12-02 16:50:31 -06:00
with open("input.txt") as file:
lines = [line.rstrip() for line in file]
first_digit = None
last_digit = None
things = []
for line in lines:
first_digit = None
last_digit = None
for letter in line:
if letter.isdigit():
if first_digit is None:
first_digit = letter
last_digit = letter
else:
last_digit = letter
things.append(int(f"{first_digit}{last_digit}"))
sum = 0
for thing in things:
sum += thing
print(sum)