adventofcode-2020/10/part2

27 lines
545 B
Plaintext
Raw Normal View History

2020-12-13 19:18:42 +01:00
#!/usr/bin/python3
from functools import lru_cache
adapters = []
with open("input") as fh:
for ln in fh:
adapters.append(int(ln))
adapters = sorted(adapters)
@lru_cache(maxsize=None)
def count(start, offset):
if offset == len(adapters) - 1:
return 1
n = 0
for i in range(offset, len(adapters)):
if adapters[i] - start < 1:
raise RuntimeError()
elif adapters[i] - start <= 3:
n += count(adapters[i], i+1)
else:
break
return n
print(count(0, 0))