import 2020 aoc

This commit is contained in:
2024-12-03 15:27:19 +01:00
parent c6c3acaa9a
commit 6b6136a8d0
32 changed files with 9708 additions and 0 deletions

24
2020/day10/day10.py Normal file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env python3
from collections import Counter
def part1(adapters):
counts = Counter()
# 1 for the socket, of 3 for the device
for current, next in zip([0] + adapters, adapters + [3]):
counts[next - current] += 1
return counts[1] * counts[3]
def part2(adapters):
counts = Counter({0: 1})
for jolt in adapters:
s = counts[jolt - 1] + counts[jolt - 2] + counts[jolt - 3]
counts[jolt] = s
return max(counts.values())
if __name__ == "__main__":
adapters = sorted(int(l.rstrip()) for l in open("input.txt"))
print(part1(adapters))
print(part2(adapters))