Compare commits

..

No commits in common. "425b1903322886e1888fa9aa370c21e592e753c7" and "fcf3add895e31ef234dffcdefdc598977ecd22d8" have entirely different histories.

2 changed files with 17 additions and 1390 deletions

View File

@ -7,33 +7,31 @@ from typing import Any
def get_reflection_value(grid: Grid, ignore: int = 0) -> int:
# search horizontal
for x in grid.rangeX():
nx = x + 1
col = grid.get_column(x)
if col == grid.get_column(nx):
if col == grid.get_column(x + 1):
match = True
for dx in range(1, grid.maxX - x):
if x - dx < 0:
break
if grid.get_column(x - dx) != grid.get_column(nx + dx):
if grid.get_column(x - dx) != grid.get_column(x + dx + 1):
match = False
break
if match and nx != ignore:
return nx
if match and x + 1 != ignore:
return x + 1
# search vertical
for y in grid.rangeY():
ny = y + 1
row = grid.get_row(y)
if row == grid.get_row(ny):
if row == grid.get_row(y + 1):
match = True
for dy in range(1, grid.maxY - y):
if y - dy < 0:
break
if grid.get_row(y - dy) != grid.get_row(ny + dy):
if grid.get_row(y - dy) != grid.get_row(y + dy + 1):
match = False
break
if match and 100 * ny != ignore:
return 100 * ny
if match and 100 * (y + 1) != ignore:
return 100 * (y + 1)
return -1
@ -42,12 +40,10 @@ class Day(AOCDay):
inputs = [
[
(405, "input13_test"),
(30158, "input13_dennis"),
(32035, "input13"),
],
[
(400, "input13_test"),
(36474, "input13_dennis"),
(24847, "input13"),
],
]
@ -62,13 +58,16 @@ class Day(AOCDay):
def part2(self) -> Any:
grids = self.parse_input()
ref_value = 0
for grid in grids:
for i, grid in enumerate(grids):
orig_ref = get_reflection_value(grid)
found = False
for x in grid.rangeX():
for y in grid.rangeY():
c = Coordinate(x, y)
grid.set(c, "." if grid.get(c) == "#" else "#")
if grid.get(c) == "#":
grid.set(c, ".")
else:
grid.set(c, "#")
v = get_reflection_value(grid, orig_ref)
if v > 0:
@ -76,7 +75,10 @@ class Day(AOCDay):
found = True
break
grid.set(c, "." if grid.get(c) == "#" else "#")
if grid.get(c) == "#":
grid.set(c, ".")
else:
grid.set(c, "#")
if found:
break

File diff suppressed because it is too large Load Diff