Day 10 (inline prod)
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import numpy as np
|
||||
import operator
|
||||
from functools import reduce
|
||||
|
||||
lines = sorted(int(x.strip()) for x in open("input.txt"))
|
||||
|
||||
@@ -11,7 +9,7 @@ lines = np.array(lines)
|
||||
diff = lines[1:] - lines[:-1]
|
||||
|
||||
one_count = 0
|
||||
possibilities = []
|
||||
possibilities = 1
|
||||
|
||||
one_cache = {}
|
||||
|
||||
@@ -25,20 +23,14 @@ def count_one_possibilities(one_cnt: int):
|
||||
return one_cache[one_cnt]
|
||||
|
||||
|
||||
def prod(iterable):
|
||||
return reduce(operator.mul, iterable, 1)
|
||||
|
||||
|
||||
# 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:
|
||||
factor = count_one_possibilities(one_count)
|
||||
if factor > 1:
|
||||
possibilities.append(factor)
|
||||
possibilities *= count_one_possibilities(one_count)
|
||||
one_count = 0
|
||||
|
||||
print(prod(possibilities)) # 64793042714624
|
||||
print(possibilities) # 64793042714624
|
||||
print(one_cache) # {0: 1, 1: 1, 2: 2, 3: 4, 4: 7}
|
||||
|
||||
Reference in New Issue
Block a user