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()