summaryrefslogtreecommitdiff
path: root/6_2021.py
blob: b8e03042f96734604a4e310edecb5f64230cc5f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
from collections import defaultdict, Counter

data = sys.argv[1] if len(sys.argv) > 1 else "../day6data.txt"
X = Counter([int(x) for x in open(data).read().strip().split(",")])


def solve(S, n):
    X = S
    for day in range(n):
        Y = defaultdict(int)
        for x, cnt in X.items():
            if x == 0:
                Y[6] += cnt
                Y[8] += cnt
            else:
                Y[x - 1] += cnt
        X = Y
    return sum(X.values())


print(solve(X, 80))
print(solve(X, 256))