-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
40 lines (31 loc) · 809 Bytes
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from GhostyUtils import aoc
if __name__ == '__main__':
inputs = aoc.read_lines()
# that sure was some awkward bullshit for day 1
m = {'one': 'o1ne',
'two': 't2wo',
'three': 't3hree',
'four': 'f4our',
'five': 'f5ive',
'six': 's6ix',
'seven': 's7even',
'eight': 'e8ight',
'nine': 'n9ine'}
# p1
sum = 0
for i in inputs:
i = ''.join(filter(str.isdigit, i))
if i:
i = f'{i[0]}{i[-1]}'
sum += int(i)
print(sum)
# p2
sum = 0
for i in inputs:
for word, replace in m.items():
i = i.replace(word, replace)
i = ''.join(filter(str.isdigit, i))
if i:
i = f'{i[0]}{i[-1]}'
sum += int(i)
print(sum)