36 lines
903 B
Python
36 lines
903 B
Python
from dataclasses import dataclass
|
|
from collections.abc import Iterator
|
|
|
|
|
|
@dataclass(init=False)
|
|
class MirrorField:
|
|
_data: list[str]
|
|
|
|
def __getitem__(self, key: int) -> str:
|
|
return self._data[key]
|
|
|
|
def __len__(self) -> int:
|
|
return len(self._data)
|
|
|
|
def __iter__(self) -> Iterator[str]:
|
|
return iter(self._data)
|
|
|
|
def iter_horizontal(self) -> Iterator[str]:
|
|
return iter(self)
|
|
|
|
def iter_vertical(self) -> Iterator[str]:
|
|
x = 0
|
|
while x < len(self._data[0]):
|
|
the_str = ""
|
|
for line in self._data:
|
|
the_str += line[x]
|
|
yield the_str
|
|
x += 1
|
|
|
|
def find_symetry(self) -> tuple[str, int] | None:
|
|
"""Return a tuple indicating a symetry horizontal (h) or vertical (v) and the first row or column index"""
|
|
|
|
|
|
def parse(input_file: str) -> MirrorField:
|
|
return MirrorField()
|