My solutions for Advent of Code.
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.
adventofcode/2020/10.py

54 lines
1023 B

4 years ago
#!/usr/bin/env python
from aoc import get_input # AoC
from functools import lru_cache
minjolt, maxjolt = 1, 3
jolts = sorted(list(map(int, get_input(10).splitlines())))
jolts.insert(0, 0) # first one is allways 0
jolts.append( max(jolts)+3 ) # my adapter, allways higher than the highest by 3
4 years ago
used = []
4 years ago
4 years ago
def getBest(i, jolts):
num = jolts[i]
4 years ago
4 years ago
diffs = []
for i in range(len(jolts)):
4 years ago
4 years ago
if( i > 0 ):
bestdiff = jolts[i] - jolts[i-1]
diffs.append(bestdiff)
4 years ago
4 years ago
diff1, diff3 = diffs.count(1), diffs.count(3)
part1 = diff1 * diff3
print(part1)
4 years ago
# part 2
@lru_cache
def countCombos(i, count=0):
num = jolts[i]
if( num != max(jolts) ):
for diff in range(1, 4):
if((num + diff) in jolts):
index = jolts.index(num + diff)
print("####", count, diff, index)
count += countCombos( index )
return count
else:
print("end")
return 1
count = countCombos(0)
print("####################", count)