-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.py
40 lines (29 loc) · 918 Bytes
/
day6.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
from typing import List
import numpy as np
input_file = "inputs/day_6.txt"
with open(input_file) as f:
data_in = [int(i) for i in f.readlines()[0].split(",")]
def init_count(inital_fish: List[int]):
counts = []
for i in range(7):
counts.append(inital_fish.count(i))
return counts
def main(days: int):
fish = init_count(data_in)
incubator = [0, 0, 0]
for idx in range(days):
n_new_fish = fish[np.mod(idx, 7)]
incubator.append(n_new_fish)
fish[np.mod(idx - 1, 7)] = fish[np.mod(idx - 1, 7)] + incubator.pop(0)
return sum(fish) + sum(incubator)
if __name__ == "__main__":
n_fish = main(80)
# part 1
print(f"Number of fishes: {n_fish}")
# part 2
import timeit
start = timeit.default_timer()
n_fish = main(256)
print(f"Number of fishes: {n_fish}")
stop = timeit.default_timer()
print("Time: ", stop - start)