d4p2 WIP
This commit is contained in:
parent
2491ef0518
commit
0cc04808b3
31
day4/run.py
31
day4/run.py
|
@ -27,8 +27,8 @@ class FindXMAS:
|
|||
return len(self.locate_xmas())
|
||||
|
||||
@property
|
||||
def _part2(self) -> None:
|
||||
pass
|
||||
def _part2(self) -> int:
|
||||
return len(self.locate_x_mas())
|
||||
|
||||
@staticmethod
|
||||
def _to_grid(input: str) -> List[List[str]]:
|
||||
|
@ -58,7 +58,7 @@ class FindXMAS:
|
|||
current.append((nx, ny))
|
||||
except IndexError:
|
||||
pass
|
||||
if len(current) == 4:
|
||||
if len(current) == len(target):
|
||||
locations.append(tuple(current))
|
||||
return locations
|
||||
|
||||
|
@ -75,6 +75,31 @@ class FindXMAS:
|
|||
|
||||
return locations
|
||||
|
||||
def locate_x_mas(self) -> List[Tuple[Tuple[int, ...]]]:
|
||||
mas: List[Tuple[Tuple[int, ...]]] = []
|
||||
|
||||
for i, line in enumerate(self.inputgrid):
|
||||
for j, char in enumerate(line):
|
||||
if char.upper() == "M":
|
||||
neighbours = [
|
||||
val
|
||||
for val in self.find_neighbours((i, j), target="MAS")
|
||||
if all([len(set(part)) == len("MAS") for part in zip(*val)])
|
||||
]
|
||||
if neighbours is None:
|
||||
continue
|
||||
mas = [*mas, *neighbours]
|
||||
|
||||
locations: List[Tuple[Tuple[int, ...]]] = []
|
||||
# breakpoint()
|
||||
for loc in mas:
|
||||
oth = [val[1] for val in mas if val != loc and val[::-1] != loc]
|
||||
# breakpoint()
|
||||
if loc[1] in oth:
|
||||
locations.append(loc)
|
||||
|
||||
return mas
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
example = FindXMAS(EXAMPLE)
|
||||
|
|
Loading…
Reference in a new issue