-
Notifications
You must be signed in to change notification settings - Fork 0
/
a06.py
47 lines (32 loc) · 760 Bytes
/
a06.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
example = """3,4,3,1,2"""
f = open("input/06.input")
text = f.read().strip()
def parse(t):
fish_timers = [int(a) for a in t.split(",")]
fish = [0] * 9
for timer in fish_timers:
fish[timer] += 1
return fish
def part1(text):
fish = parse(text)
for _ in range(80):
fish = tick(fish)
return sum(fish)
def tick(fish):
result = [0] * 9
result[8] = fish[0]
for idx in range(1, len(fish)):
result[idx - 1] += fish[idx]
result[6] += fish[0]
return result
def part2(text):
fish = parse(text)
for _ in range(256):
fish = tick(fish)
return sum(fish)
def main(text):
print("Part1:", part1(text))
print("Part2:", part2(text))
main(example)
print()
main(text)