-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.py
48 lines (32 loc) · 1004 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
40
41
42
43
44
45
46
47
48
with open("input6.txt", 'r') as file:
fish = list(map(int, file.readline().split(',')))
""" def nexnday(fish, n):
a = list(map(lambda x: x-n, fish))
for i in range(len(a)):
if a[i] == -1:
a[i] = 6
a.append(8)
return a, len(a)
fish = [3, 4, 3, 1, 2]
i = 0
while i < 150:
p = min(fish) + 1
fish, schoolsize = nexnday(fish, p)
i += p
print(schoolsize)
"""
# fish = [3, 4, 3, 1, 2]
fishcnt = {i: fish.count(i) for i in range(9)}
# print(fishcnt)
def nextday(fishdata):
updatedfishdata = {i: fishdata[i+1] for i in range(8)}
updatedfishdata[6] += fishdata[0]
updatedfishdata[8] = fishdata[0]
return updatedfishdata
def populationonnthday(n, fishcnt):
for _ in range(n):
fishcnt = nextday(fishcnt)
return sum(fishcnt.values())
with open("output.txt", 'w') as file:
for i in range(50):
file.write(f"(\\ln({populationonnthday(i,fishcnt)})),")