more d22p2 fiddling; maybe think about a whole new approach
This commit is contained in:
parent
e3da4a09bf
commit
8dd26033e3
55
day22.py
55
day22.py
@ -1,7 +1,7 @@
|
||||
import re
|
||||
from tools.aoc import AOCDay
|
||||
from tools.coordinate import Coordinate
|
||||
from tools.grid import Grid, GridTransformation
|
||||
from tools.grid import Grid
|
||||
from typing import Any
|
||||
|
||||
|
||||
@ -13,8 +13,6 @@ FACING = [
|
||||
]
|
||||
|
||||
CUBE_CONNECTIONS = {
|
||||
'.#./###/.#./.#.': 1,
|
||||
'###/.#./.#./.#.': 2,
|
||||
'##./.#./.##/..#': (
|
||||
((0, 0, 1), (1, 1, 0)),
|
||||
((0, 0, 2), (1, 2, 0)),
|
||||
@ -31,12 +29,22 @@ CUBE_CONNECTIONS = {
|
||||
((2, 3, 1), (0, 0, 1)),
|
||||
((2, 3, 2), (1, 2, 3)),
|
||||
),
|
||||
'##./.#./.##/.#.': 4,
|
||||
'.#./##./.##/.#.': 5,
|
||||
'.##/.#./.#./##.': 6,
|
||||
'.##/##./.#./.#.': 7,
|
||||
'..#/.##/##./#..': 8,
|
||||
'.#./.##/##./#..': 9,
|
||||
'..#./###./..##': (
|
||||
((2, 0, 0), (3, 2, 2)),
|
||||
((2, 0, 2), (1, 1, 1)),
|
||||
((2, 0, 3), (0, 1, 1)),
|
||||
((0, 1, 1), (2, 2, 3)),
|
||||
((0, 1, 2), (3, 2, 3)),
|
||||
((0, 1, 3), (2, 0, 1)),
|
||||
((1, 1, 1), (2, 2, 0)),
|
||||
((1, 1, 3), (2, 0, 0)),
|
||||
((2, 1, 0), (3, 2, 1)),
|
||||
((2, 2, 1), (0, 1, 3)),
|
||||
((2, 2, 2), (1, 1, 3)),
|
||||
((3, 2, 0), (2, 0, 2)),
|
||||
((3, 2, 1), (0, 1, 0)),
|
||||
((3, 2, 3), (2, 1, 2)),
|
||||
),
|
||||
'.#./.#./###/#..': (
|
||||
((1, 0, 0), (2, 2, 2)),
|
||||
((1, 0, 2), (0, 2, 0)),
|
||||
@ -53,7 +61,6 @@ CUBE_CONNECTIONS = {
|
||||
((0, 3, 1), (2, 2, 1)),
|
||||
((0, 3, 2), (1, 0, 1)),
|
||||
),
|
||||
'.#/.#/##/#./#.': 11,
|
||||
}
|
||||
|
||||
|
||||
@ -69,6 +76,13 @@ def get_cube_conn_dict(cube_conn: tuple, c_size: int) -> dict:
|
||||
tar_x, tar_y, tar_f = tar
|
||||
|
||||
match cur_f, tar_f:
|
||||
case 0, 1:
|
||||
x = (cur_x + 1) * c_size - 1
|
||||
ty = tar_y * c_size
|
||||
for d in range(c_size):
|
||||
y = cur_y * c_size + d
|
||||
tx = (tar_x + 1) * c_size - (d + 1)
|
||||
conn_dict[(x, y, cur_f)] = (Coordinate(tx, ty), tar_f)
|
||||
case 0, 2:
|
||||
x = (cur_x + 1) * c_size - 1
|
||||
tx = (tar_x + 1) * c_size - 1
|
||||
@ -139,6 +153,13 @@ def get_cube_conn_dict(cube_conn: tuple, c_size: int) -> dict:
|
||||
x = cur_x * c_size + d
|
||||
ty = tar_y * c_size + d
|
||||
conn_dict[(x, y, cur_f)] = (Coordinate(tx, ty), tar_f)
|
||||
case 3, 1:
|
||||
y = cur_y * c_size
|
||||
ty = (tar_y + 1) * c_size - 1
|
||||
for d in range(c_size):
|
||||
x = cur_x * c_size + d
|
||||
tx = tar_x * c_size + d
|
||||
conn_dict[(x, y, cur_f)] = (Coordinate(tx, ty), tar_f)
|
||||
case 3, 2:
|
||||
y = cur_y * c_size
|
||||
tx = (tar_x + 1) * c_size - 1
|
||||
@ -176,23 +197,17 @@ def identify_cube(board: Grid) -> dict:
|
||||
if cube_grid.getOnCount() != 6:
|
||||
continue
|
||||
|
||||
print(cube_grid)
|
||||
|
||||
for _ in range(2):
|
||||
for _ in range(4):
|
||||
board.transform(GridTransformation.ROTATE_RIGHT)
|
||||
cube_grid.transform(GridTransformation.ROTATE_RIGHT)
|
||||
cube_grid.print(true_char='#')
|
||||
if str(cube_grid) in CUBE_CONNECTIONS:
|
||||
return get_cube_conn_dict(CUBE_CONNECTIONS[str(cube_grid)], x_size)
|
||||
board.transform(GridTransformation.FLIP_X)
|
||||
cube_grid.transform(GridTransformation.FLIP_X)
|
||||
|
||||
print("FUCK")
|
||||
print("Unknown Cube-Shape")
|
||||
|
||||
|
||||
def walk(board: Grid, pos: Coordinate, directions: list, face: int = 0, connections: dict = None) -> (Coordinate, int):
|
||||
for direction in directions:
|
||||
steps, turn = direction
|
||||
print("starting at", pos, "moving", steps, "steps, then turning", turn)
|
||||
|
||||
for _ in range(steps):
|
||||
next_pos = pos + FACING[face]
|
||||
@ -200,6 +215,7 @@ def walk(board: Grid, pos: Coordinate, directions: list, face: int = 0, connecti
|
||||
if board.get(next_pos) is None or not board.isWithinBoundaries(next_pos):
|
||||
if connections is not None:
|
||||
next_pos, next_face = connections[(pos.x, pos.y, face)]
|
||||
print("wrapping from", pos, "to", next_pos, "facing", next_face)
|
||||
else:
|
||||
match face:
|
||||
case 0:
|
||||
@ -266,7 +282,6 @@ class Day(AOCDay):
|
||||
def part2(self) -> Any:
|
||||
board_map, directions, start_position = self.get_map_and_directions()
|
||||
conn = identify_cube(board_map)
|
||||
board_map.bla()
|
||||
for x in board_map.rangeX():
|
||||
c = Coordinate(x, 0)
|
||||
if board_map.get(c) is not None:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user