Solve 10.1 and 10.2

This commit is contained in:
2021-05-03 23:04:15 +03:00
parent 152c9a1911
commit 8654551014
2 changed files with 125 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
with open("input") as f:
adapters = [int(x) for x in f.read().strip().split("\n")]
adapters.extend([0, max(adapters)+3])
adapters.sort()
joltages = [b-a for a, b in zip(adapters, adapters[1:])]
print(joltages.count(1)*joltages.count(3))
joltages = ''.join(str(x) for x in joltages)
joltages = joltages.split('3')
counts = {
'': 1,
'1': 1,
'11': 2,
'111': 4,
'1111': 7,
}
from functools import reduce
print(reduce(lambda x, y: x*counts[y], joltages, 1))