-
Notifications
You must be signed in to change notification settings - Fork 0
/
day-1.py
48 lines (35 loc) · 844 Bytes
/
day-1.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
41
42
43
44
45
46
47
48
#!/usr/bin/env python
def partOne(input):
maxValue = 0
i = 0
curr = 0
while (i < len(input)):
if not input[i]:
maxValue = max(maxValue, curr)
curr = 0
i += 1
continue
curr += int(input[i])
i += 1
return maxValue
def partTwo(input):
maxValue = 0
curr = 0
maxArray = []
for line in input:
if not line:
maxArray.append(curr)
if len(maxArray) > 3:
maxArray.sort()
maxArray.pop(0)
curr = 0
continue
curr += int(line)
return sum(maxArray)
def main():
f = open('./input/day-1.txt', 'r')
input = f.read().splitlines()
print(partOne(input))
print(partTwo(input))
if __name__ == '__main__':
main()