From 06ac7e2b6db22fbe483e86500cd32f9a5eb9dd88 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Thu, 14 Dec 2023 09:56:21 +0100 Subject: [PATCH] day 14 part 1 --- aoc/day14.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 aoc/day14.py diff --git a/aoc/day14.py b/aoc/day14.py new file mode 100644 index 0000000..6bc6b69 --- /dev/null +++ b/aoc/day14.py @@ -0,0 +1,49 @@ +from __future__ import annotations +from typing import TypeAlias +from collections import defaultdict + +from .aoc import Aoc2, AocSameParser +from .day11 import Matrix + +P1: TypeAlias = Matrix +P2: TypeAlias = Matrix + + +class Day14(AocSameParser[P1], Aoc2[P1, P2]): + def parseinput(self, inpt: str) -> P1: + return Matrix(inpt) + + def part1(self, inpt: P1) -> int: + pos_matrix = {} + for y in range(0, inpt.height): # enumerate(inpt.iter_rows()): + for x in range(0, inpt.width): # enumerate(line): + pos_matrix[x, y] = (x, y) + if y > 0: + if inpt[x, y - 1] == ".": + pos_matrix[x, y] = pos_matrix[x, y - 1] + if inpt[x, y - 1] == "O": + p = pos_matrix[x, y - 1] + pos_matrix[x, y] = (p[0], p[1] + 1) + + accum = 0 + for o in inpt.finditer("O"): + # print( + # f"{o} -> {pos_matrix[(o.x,o.y)]} ({inpt.height - pos_matrix[(o.x,o.y)][1]})" + # ) + accum += inpt.height - pos_matrix[(o.x, o.y)][1] + + print(accum) + + return accum + + def part2(self, inpt: P2) -> int: + return 0 + + +def main() -> None: + aoc = Day14(2023, 14) + aoc.run() + + +if __name__ == "__main__": + main()