mirror of
https://github.com/thib8956/advent-of-code.git
synced 2025-08-24 08:21:57 +00:00
chore: create new project structure and aoc.py runner script
This commit is contained in:
30
adventofcode/2020/day10/day10.py
Normal file
30
adventofcode/2020/day10/day10.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/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())
|
||||
|
||||
|
||||
def main(f):
|
||||
adapters = sorted(int(l.rstrip()) for l in f)
|
||||
print(part1(adapters))
|
||||
print(part2(adapters))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import fileinput
|
||||
main(fileinput.input())
|
||||
|
Reference in New Issue
Block a user