2023 - Day 1 part 1

This commit is contained in:
kleph 2023-12-01 13:57:44 +01:00
parent 8829205e08
commit a2449062b2
3 changed files with 1025 additions and 0 deletions

21
2023/1/1.py Normal file
View file

@ -0,0 +1,21 @@
#!/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}")

1000
2023/1/input.txt Normal file

File diff suppressed because it is too large Load diff

4
2023/1/input_example.txt Normal file
View file

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet