Skip to content

Commit 23731d7

Browse files
committed
Day 06
1 parent a2e06b8 commit 23731d7

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

day_06/__init__.py

Whitespace-only changes.

day_06/__main__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import TextIO, Dict
2+
from collections import defaultdict
3+
import sys
4+
5+
NEW_FISH_AGE=8
6+
POST_REPRODUCTION_AGE=6
7+
8+
def step(input_state: Dict[int, int]) -> Dict[int, int]:
9+
output_state = defaultdict(lambda: 0)
10+
output_state[NEW_FISH_AGE] = input_state[0]
11+
output_state[POST_REPRODUCTION_AGE] = input_state[0]
12+
for i in range(1, NEW_FISH_AGE+1):
13+
output_state[i-1] += input_state[i]
14+
return output_state
15+
16+
def read_input(textio: TextIO) -> Dict[int, int]:
17+
state = defaultdict(lambda: 0)
18+
ages = [int(num) for num in textio.readlines()[0].split(',')]
19+
for age in ages:
20+
state[age] += 1
21+
return state
22+
23+
def print_state(state: Dict[int, int]):
24+
for i in range(NEW_FISH_AGE+1):
25+
print(f"{i}: {state[i]}")
26+
27+
state = read_input(sys.stdin)
28+
29+
for iteration in range(257):
30+
print(f"Iteration {iteration}")
31+
print("Count: %d" % sum(state.values()))
32+
print_state(state)
33+
state = step(state)
34+
print()

day_06/input

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3,5,4,1,2,1,5,5,1,1,1,1,4,1,4,5,4,5,1,3,1,1,1,4,1,1,3,1,1,5,3,1,1,3,1,3,1,1,1,4,1,2,5,3,1,4,2,3,1,1,2,1,1,1,4,1,1,1,1,2,1,1,1,3,1,1,4,1,4,1,5,1,4,2,1,1,5,4,4,4,1,4,1,1,1,1,3,1,5,1,4,5,3,1,4,1,5,2,2,5,1,3,2,2,5,4,2,3,4,1,2,1,1,2,1,1,5,4,1,1,1,1,3,1,5,4,1,5,1,1,4,3,4,3,1,5,1,1,2,1,1,5,3,1,1,1,1,1,5,1,1,1,1,1,1,1,2,2,5,5,1,2,1,2,1,1,5,1,3,1,5,2,1,4,1,5,3,1,1,1,2,1,3,1,4,4,1,1,5,1,1,4,1,4,2,3,5,2,5,1,3,1,2,1,4,1,1,1,1,2,1,4,1,3,4,1,1,1,1,1,1,1,2,1,5,1,1,1,1,2,3,1,1,2,3,1,1,3,1,1,3,1,3,1,3,3,1,1,2,1,3,2,3,1,1,3,5,1,1,5,5,1,2,1,2,2,1,1,1,5,3,1,1,3,5,1,3,1,5,3,4,2,3,2,1,3,1,1,3,4,2,1,1,3,1,1,1,1,1,1

day_06/test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3,4,3,1,2

0 commit comments

Comments
 (0)