[py] Port 2018_01

This commit is contained in:
Joscha 2022-12-06 15:16:01 +01:00
parent 0272942104
commit 31d6098c58
4 changed files with 19 additions and 38 deletions

View file

@ -2,11 +2,13 @@ import sys
import argparse
from pathlib import Path
from .y2018 import d01
from .y2020 import d10
from .y2021 import d14
from .y2022 import d01, d02, d03, d04, d05, d06
DAYS = {
"2018_01": y2018.d01.solve,
"2020_10": y2020.d10.solve,
"2021_14": y2021.d14.solve,
"2022_01": y2022.d01.solve,

17
py/aoc/y2018/d01.py Normal file
View file

@ -0,0 +1,17 @@
def find_repeat(freqs):
total = 0
found = {total}
while True:
for n in freqs:
total += n
if total in found:
return total
else:
found.add(total)
def solve(inputstr):
freqs = [int(freq) for freq in inputstr.splitlines()]
print(f"Part 1: {sum(freqs)}")
print(f"Part 2: {find_repeat(freqs)}")