generated from public/aoc_template
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
a887c3f6fd
32
day13.py
32
day13.py
@ -7,31 +7,33 @@ from typing import Any
|
|||||||
def get_reflection_value(grid: Grid, ignore: int = 0) -> int:
|
def get_reflection_value(grid: Grid, ignore: int = 0) -> int:
|
||||||
# search horizontal
|
# search horizontal
|
||||||
for x in grid.rangeX():
|
for x in grid.rangeX():
|
||||||
|
nx = x + 1
|
||||||
col = grid.get_column(x)
|
col = grid.get_column(x)
|
||||||
if col == grid.get_column(x + 1):
|
if col == grid.get_column(nx):
|
||||||
match = True
|
match = True
|
||||||
for dx in range(1, grid.maxX - x):
|
for dx in range(1, grid.maxX - x):
|
||||||
if x - dx < 0:
|
if x - dx < 0:
|
||||||
break
|
break
|
||||||
if grid.get_column(x - dx) != grid.get_column(x + dx + 1):
|
if grid.get_column(x - dx) != grid.get_column(nx + dx):
|
||||||
match = False
|
match = False
|
||||||
break
|
break
|
||||||
if match and x + 1 != ignore:
|
if match and nx != ignore:
|
||||||
return x + 1
|
return nx
|
||||||
|
|
||||||
# search vertical
|
# search vertical
|
||||||
for y in grid.rangeY():
|
for y in grid.rangeY():
|
||||||
|
ny = y + 1
|
||||||
row = grid.get_row(y)
|
row = grid.get_row(y)
|
||||||
if row == grid.get_row(y + 1):
|
if row == grid.get_row(ny):
|
||||||
match = True
|
match = True
|
||||||
for dy in range(1, grid.maxY - y):
|
for dy in range(1, grid.maxY - y):
|
||||||
if y - dy < 0:
|
if y - dy < 0:
|
||||||
break
|
break
|
||||||
if grid.get_row(y - dy) != grid.get_row(y + dy + 1):
|
if grid.get_row(y - dy) != grid.get_row(ny + dy):
|
||||||
match = False
|
match = False
|
||||||
break
|
break
|
||||||
if match and 100 * (y + 1) != ignore:
|
if match and 100 * ny != ignore:
|
||||||
return 100 * (y + 1)
|
return 100 * ny
|
||||||
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@ -40,10 +42,12 @@ class Day(AOCDay):
|
|||||||
inputs = [
|
inputs = [
|
||||||
[
|
[
|
||||||
(405, "input13_test"),
|
(405, "input13_test"),
|
||||||
|
(30158, "input13_dennis"),
|
||||||
(32035, "input13"),
|
(32035, "input13"),
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
(400, "input13_test"),
|
(400, "input13_test"),
|
||||||
|
(36474, "input13_dennis"),
|
||||||
(24847, "input13"),
|
(24847, "input13"),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
@ -58,16 +62,13 @@ class Day(AOCDay):
|
|||||||
def part2(self) -> Any:
|
def part2(self) -> Any:
|
||||||
grids = self.parse_input()
|
grids = self.parse_input()
|
||||||
ref_value = 0
|
ref_value = 0
|
||||||
for i, grid in enumerate(grids):
|
for grid in grids:
|
||||||
orig_ref = get_reflection_value(grid)
|
orig_ref = get_reflection_value(grid)
|
||||||
found = False
|
found = False
|
||||||
for x in grid.rangeX():
|
for x in grid.rangeX():
|
||||||
for y in grid.rangeY():
|
for y in grid.rangeY():
|
||||||
c = Coordinate(x, y)
|
c = Coordinate(x, y)
|
||||||
if grid.get(c) == "#":
|
grid.set(c, "." if grid.get(c) == "#" else "#")
|
||||||
grid.set(c, ".")
|
|
||||||
else:
|
|
||||||
grid.set(c, "#")
|
|
||||||
|
|
||||||
v = get_reflection_value(grid, orig_ref)
|
v = get_reflection_value(grid, orig_ref)
|
||||||
if v > 0:
|
if v > 0:
|
||||||
@ -75,10 +76,7 @@ class Day(AOCDay):
|
|||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if grid.get(c) == "#":
|
grid.set(c, "." if grid.get(c) == "#" else "#")
|
||||||
grid.set(c, ".")
|
|
||||||
else:
|
|
||||||
grid.set(c, "#")
|
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
break
|
break
|
||||||
|
|||||||
1375
inputs/input13_dennis
Normal file
1375
inputs/input13_dennis
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user