"""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))