-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.py
40 lines (32 loc) · 848 Bytes
/
day1.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
# Press the green button in the gutter to run the script.
def part1():
count = 0
prev = 99999
with open('resources/input1.txt') as f:
lines = f.readlines()
for line in lines:
val = int(line)
if val > prev:
count = count + 1
prev = val
print(count)
def part2():
count = 0
prev1 = 99999
prev2 = 99999
prev3 = 99999
with open('resources/input1.txt') as f:
lines = f.readlines()
for line in lines:
val = int(line)
prevTotal = prev1 + prev2 + prev3
total = val + prev1 + prev2
if total > prevTotal:
count = count + 1
prev3 = prev2
prev2 = prev1
prev1 = val
print(count)
if __name__ == '__main__':
part1()
part2()