aoc2023/aoc/day12.py
2023-12-13 14:15:19 +01:00

60 lines
1.3 KiB
Python

from __future__ import annotations
from typing import TypeAlias
from dataclasses import dataclass
from itertools import groupby, takewhile
from collections import deque
from .aoc import Aoc2, AocParseLines
"""
?###???????? 3,2,1
"""
@dataclass
class Line:
springs: str
spring_groups: deque[tuple[int, str]]
groups: list[int]
@classmethod
def from_str(cls, inpt: str) -> Line:
springs, groups_str = inpt.split(" ")
groups = [int(d) for d in groups_str.split(",")]
springs_group = deque((len(list(d)), i) for i, d in groupby(springs))
return Line(springs, springs_group, groups)
P1: TypeAlias = list[Line]
P2: TypeAlias = list[Line]
class Day12(AocParseLines[Line, Line], Aoc2[P1, P2]):
def parseline1(self, inpt: str) -> Line:
return Line.from_str(inpt)
def parseline2(self, inpt: str) -> Line:
return Line.from_str(inpt)
def part1(self, inpt: P1) -> int:
for line in inpt:
sgroups = line.spring_groups
for group in line.groups:
batch = takewhile(lambda g: g[1] != ".", sgroups)
first_group = sgroups.popleft()
return 0
def part2(self, inpt: P2) -> int:
return 0
def main() -> None:
aoc = Day12(2023, 12, example_code_nr1=1)
aoc.run_example_1()
if __name__ == "__main__":
main()