#!/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))