-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.py
More file actions
32 lines (24 loc) · 788 Bytes
/
day1.py
File metadata and controls
32 lines (24 loc) · 788 Bytes
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
""" ADVENT OF CODE day 1 """
import numpy as np
list = np.loadtxt("input1.txt", dtype=int)
count_1 = 0
for i in range(1, len(list)):
if list[i] > list[i - 1]:
count_1 += 1
print(count_1)
count_2 = 0
last_value = list[0] + list[1] + list[2]
for i in range(1, len(list) - 2):
if list[i] + list[i + 1] + list[i + 2] > last_value:
count_2 += 1
last_value = list[i] + list[i + 1] + list[i + 2]
print(count_2)
# one function solution
def get_increase_count(sequence, window_size=1):
count_increase = 0
for i in range(len(sequence) - window_size):
if sequence[i] < sequence[i + window_size]:
count_increase += 1
return count_increase
print("Part 1:\t", get_increase_count(list))
print("Part 2:\t", get_increase_count(list, 3))