[py] Port 2020_10

This commit is contained in:
Joscha 2022-12-04 14:38:19 +01:00
parent 81945a973d
commit bd2dd9a4f9
5 changed files with 149 additions and 9 deletions

View file

@ -2,10 +2,12 @@ import sys
import argparse
from pathlib import Path
from .y2020 import d10
from .y2021 import d14
from .y2022 import d01, d02, d03, d04
DAYS = {
"2020_10": y2020.d10.solve,
"2021_14": y2021.d14.solve,
"2022_01": y2022.d01.solve,
"2022_02": y2022.d02.solve,

11
py/aoc/y2020/d10.py Normal file
View file

@ -0,0 +1,11 @@
def solve(inputstr):
values = list(sorted(int(i) for i in inputstr.splitlines()))
values.append(max(values) + 3)
diffs = [y - x for x, y in zip([0] + values, values)]
print(f"Part 1: {diffs.count(1) * diffs.count(3)}")
combinations = [1] + [0] * max(values)
for adapter in values:
combinations[adapter] = sum(combinations[max(0, adapter - 3) : adapter])
print(f"Part 2: {combinations[-1]}")