37 lines
875 B
Python
37 lines
875 B
Python
import numpy as np
|
|
|
|
lines = sorted(int(x.strip()) for x in open("input.txt"))
|
|
|
|
lines.append(lines[-1]+3)
|
|
lines.insert(0, 0)
|
|
lines = np.array(lines)
|
|
|
|
diff = lines[1:] - lines[:-1]
|
|
|
|
one_count = 0
|
|
possibilities = 1
|
|
|
|
one_cache = {}
|
|
|
|
|
|
def count_one_possibilities(one_cnt: int):
|
|
if one_cnt not in one_cache:
|
|
if one_cnt <= 1:
|
|
one_cache[one_cnt] = 1
|
|
else:
|
|
one_cache[one_cnt] = sum(count_one_possibilities(less) for less in range(max(0, one_cnt - 3), one_cnt))
|
|
return one_cache[one_cnt]
|
|
|
|
|
|
# only 3 and 1 differences are available
|
|
# 3 has to be taken / calculate possibilities for 1 hops
|
|
for num in diff:
|
|
if num == 1:
|
|
one_count += 1
|
|
elif num == 3:
|
|
possibilities *= count_one_possibilities(one_count)
|
|
one_count = 0
|
|
|
|
print(possibilities) # 64793042714624
|
|
print(one_cache) # {0: 1, 1: 1, 2: 2, 3: 4, 4: 7}
|