Day 6 part 1
This commit is contained in:
parent
6a3d40a488
commit
a5626235d3
3 changed files with 32 additions and 0 deletions
30
6/6.py
Executable file
30
6/6.py
Executable file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# 2021 - Advent Of Code - 6
|
||||||
|
|
||||||
|
def parse_file(file):
|
||||||
|
with open(file) as f:
|
||||||
|
line = f.readline()
|
||||||
|
return [int(x) for x in line.split(',')]
|
||||||
|
|
||||||
|
|
||||||
|
def iterate(state):
|
||||||
|
new_fish = 0
|
||||||
|
for i in range(len(state)):
|
||||||
|
if state[i] == 0:
|
||||||
|
new_fish += 1
|
||||||
|
state[i] = 6
|
||||||
|
else:
|
||||||
|
state[i] -= 1
|
||||||
|
state.extend([8]*new_fish)
|
||||||
|
|
||||||
|
|
||||||
|
init_state = parse_file('input.txt')
|
||||||
|
print(f'Initial state: {init_state}')
|
||||||
|
|
||||||
|
DAYS = 80
|
||||||
|
|
||||||
|
for d in range(DAYS):
|
||||||
|
iterate(init_state)
|
||||||
|
# print(f'After {d+1:2} days: {init_state}')
|
||||||
|
|
||||||
|
print(f'There\'s {len(init_state)} lanterfish after {DAYS} days')
|
1
6/input.txt
Normal file
1
6/input.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3,5,3,1,4,4,5,5,2,1,4,3,5,1,3,5,3,2,4,3,5,3,1,1,2,1,4,5,3,1,4,5,4,3,3,4,3,1,1,2,2,4,1,1,4,3,4,4,2,4,3,1,5,1,2,3,2,4,4,1,1,1,3,3,5,1,4,5,5,2,5,3,3,1,1,2,3,3,3,1,4,1,5,1,5,3,3,1,5,3,4,3,1,4,1,1,1,2,1,2,3,2,2,4,3,5,5,4,5,3,1,4,4,2,4,4,5,1,5,3,3,5,5,4,4,1,3,2,3,1,2,4,5,3,3,5,4,1,1,5,2,5,1,5,5,4,1,1,1,1,5,3,3,4,4,2,2,1,5,1,1,1,4,4,2,2,2,2,2,5,5,2,4,4,4,1,2,5,4,5,2,5,4,3,1,1,5,4,5,3,2,3,4,1,4,1,1,3,5,1,2,5,1,1,1,5,1,1,4,2,3,4,1,3,3,2,3,1,1,4,4,3,2,1,2,1,4,2,5,4,2,5,3,2,3,3,4,1,3,5,5,1,3,4,5,1,1,3,1,2,1,1,1,1,5,1,1,2,1,4,5,2,1,5,4,2,2,5,5,1,5,1,2,1,5,2,4,3,2,3,1,1,1,2,3,1,4,3,1,2,3,2,1,3,3,2,1,2,5,2
|
1
6/input_example.txt
Normal file
1
6/input_example.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3,4,3,1,2
|
Loading…
Reference in a new issue