blob: b0e5d8b4e4b744aa9fcdadff5ee072eda85374e7 (
plain) (
blame)
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
29
30
31
32
|
#!/usr/bin/env python3
adaptors: list[str]
def combos(i: int, counts: dict[int, dict[int, int]] = {}) -> int:
if i == len(adaptors) - 1:
return 1
if i in counts:
return counts[i]
counts[i] = sum(
combos(j, counts) if adaptors[j] - adaptors[i] <= 3 else 0
for j in range(i + 1, len(adaptors))
)
return counts[i]
def main() -> None:
global adaptors
with open("input", "r", encoding="utf-8") as f:
adaptors = list(map(int, f.readlines()))
adaptors.append(0)
adaptors.sort()
adaptors.append(adaptors[-1] + 3)
print(combos(0))
if __name__ == "__main__":
main()
|