Skip to content

Commit 596bacf

Browse files
committed
2023 day1 part1
1 parent 1013ac7 commit 596bacf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2023/day1part1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# utility functions
2+
def first_digit(input_str):
3+
for curr_ch in input_str:
4+
if curr_ch.isdigit():
5+
return curr_ch
6+
7+
return -1
8+
9+
def last_digit(input_str): return first_digit(reversed(input_str))
10+
11+
# input & process line-by-line
12+
counter = 0
13+
with open("day1.in", "r") as fin:
14+
for line in fin:
15+
curr = int(first_digit(line) + last_digit(line))
16+
counter += curr
17+
18+
# output
19+
print(counter)

0 commit comments

Comments
 (0)