day 14 part 1
This commit is contained in:
parent
36094741a5
commit
06ac7e2b6d
1 changed files with 49 additions and 0 deletions
49
aoc/day14.py
Normal file
49
aoc/day14.py
Normal file
|
@ -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()
|
Loading…
Add table
Reference in a new issue