From 3688946a24c7e324148278e5128a3a1559a9a854 Mon Sep 17 00:00:00 2001 From: Christoph Stahl Date: Fri, 15 Dec 2023 10:13:37 +0100 Subject: [PATCH] precomputed rotated matrix in Matrix class --- aoc/day11.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/aoc/day11.py b/aoc/day11.py index 5eb3aae..2e7ef68 100644 --- a/aoc/day11.py +++ b/aoc/day11.py @@ -40,9 +40,13 @@ class Matrix: self.height = len(lines) self.width = len(lines[0]) self.array = array("u") + self.array_rot = array("u") for line in lines: self.array.fromlist(list(line)) + for line in zip(*lines): + self.array_rot.fromlist(list(line)) + def __getitem__(self, pos: Position | tuple[int, int]) -> str: return self.array[self.width * pos[1] + pos[0]] @@ -56,7 +60,8 @@ class Matrix: return (self.get_row(y) for y in range(self.height)) def get_col(self, col_no: int) -> array[str]: - return array("u", [self[col_no, y] for y in range(self.height)]) + return self.array_rot[self.height * col_no : self.width * (col_no + 1)] + # return array("u", [self[col_no, y] for y in range(self.height)]) def iter_cols(self) -> Iterable[array[str]]: return (self.get_col(x) for x in range(self.width))