summaryrefslogtreecommitdiff
path: root/day10/day10.py
blob: 041c7588b1974dd93e3e322d4ce5e4609dc945b1 (plain)
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
"""Day 10."""
from collections import Counter
from itertools import combinations
from functools import lru_cache

with open("input") as f:
    orig_nums = sorted([int(x) for x in f.read().rstrip().split("\n")])

rated_for = orig_nums[-1] + 3
nums = [0] + orig_nums + [rated_for]
diffs = [j - i for i, j in list(zip(nums[:-1], nums[1:]))]
counter = Counter(diffs)

# Part 1
print(counter[1] * counter[3])

@lru_cache(None)
def arrangements(jolts, prev) -> int:
    first, rest = jolts[0], jolts[1:]
    if first - prev > 3:
        return 0
    elif not rest:
        return 1
    else:
        return (arrangements(rest, first) + # Use first
                arrangements(rest, prev))   # Skip first

print(arrangements(tuple(orig_nums), 0))