-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.py
50 lines (33 loc) · 926 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
49
def get_next_state(state):
nr_baby_fishies = 0
for fish in range(0, len(state)):
if state[fish] > 0:
state[fish] -= 1
elif state[fish] == 0:
state[fish] = 6
nr_baby_fishies += 1
babies = [8]*nr_baby_fishies
state = state + babies
return state
input_file = 'input6'
with open(input_file) as f:
lines = f.readlines()
end_day = 256
initial_state = (lines[0].strip()).split(',')
print(initial_state)
state = [int(i) for i in initial_state]
fishies = [0]*9
for i in state:
fishies[i] += 1
for i in range(0, end_day):
ready_fishies = fishies[0]
fishies[0] = 0
for k in range(1, 9):
fishies[k-1] = fishies[k]
fishies[8] = ready_fishies
fishies[6] += ready_fishies
print(fishies)
nr_fishies = 0
for i in fishies:
nr_fishies += i
print('nr of fish after ', end_day, ' days : ', nr_fishies)