From eabcdb3e2d10c24710af73c46591f25a6d2b08db Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Wed, 13 Dec 2023 14:15:19 +0100 Subject: [PATCH] Day12 something --- aoc/day12.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 aoc/day12.py diff --git a/aoc/day12.py b/aoc/day12.py new file mode 100644 index 0000000..f919fd0 --- /dev/null +++ b/aoc/day12.py @@ -0,0 +1,60 @@ +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()