You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1015 B
58 lines
1015 B
|
|
|
|
def adapter_chain(adapts):
|
|
jolt1 = 0
|
|
jolt3 = 1
|
|
for i in range(1, len(adapts)):
|
|
if adapts[i-1] - adapts[i] == 1:
|
|
jolt1 += 1
|
|
elif adapts[i-1] - adapts[i] == 3:
|
|
jolt3 += 1
|
|
else:
|
|
print(adapts[i] - adapts[i-1])
|
|
return jolt1 * jolt3
|
|
|
|
|
|
def memo(f):
|
|
memo = {}
|
|
|
|
def f2(x):
|
|
if x not in memo:
|
|
memo[x] = f(x)
|
|
return memo[x]
|
|
|
|
return f2
|
|
|
|
|
|
@memo
|
|
def combinations(i):
|
|
j = 0
|
|
if i == max(nums):
|
|
return 1
|
|
if i+1 in nums:
|
|
j += combinations(i+1)
|
|
if i+2 in nums:
|
|
j += combinations(i+2)
|
|
if i+3 in nums:
|
|
j += combinations(i+3)
|
|
return j
|
|
|
|
|
|
with open(r"C:\Users\Maya\Desktop\Uni\WS_2021\AoC\input10") as f:
|
|
lines = f.readlines()
|
|
|
|
# convert to integers
|
|
nums = [int(line) for line in lines]
|
|
nums.append(0)
|
|
nums.sort()
|
|
|
|
nums.reverse()
|
|
|
|
print(adapter_chain(nums))
|
|
|
|
nums.append(nums[-1] + 3)
|
|
nums.reverse()
|
|
|
|
|
|
|
|
print(combinations(0))
|
|
|