Start day 22.

This commit is contained in:
Mikael CAPELLE 2022-12-22 08:20:09 +01:00
parent b656e8929e
commit 3934dfd152
4 changed files with 253 additions and 0 deletions

View File

@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
from __future__ import annotations
import sys import sys

View File

@ -1,3 +1,38 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
import re
import sys import sys
import numpy as np
EMPTY = 0
VOID = 1
WALL = 2
TILE_FROM_CHAR = {" ": VOID, ".": EMPTY, "#": WALL}
board_map_s, direction_s = sys.stdin.read().split("\n\n")
# board
board_lines = board_map_s.splitlines()
max_line = max(len(line) for line in board_lines)
board_map = np.array(
[
[TILE_FROM_CHAR[c] for c in row] + [VOID] * (max_line - len(row))
for row in board_map_s.splitlines()
]
)
directions = [
int(p1) if p2 else p1 for p1, p2 in re.findall(R"(([0-9])+|L|R)", direction_s)
]
y0 = 0
x0 = np.where(board_map[0] == EMPTY)[0][0]
r0 = "R"
print(y0, x0)
for direction in directions:
if isinstance(direction, int):
if r0 == "R":
x0 = np.argmax(board_map[y0, x0 + 1 :])

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,14 @@
...#
.#..
#...
....
...#.......#
........#...
..#....#....
..........#.
...#....
.....#..
.#......
......#.
10R5L5R10L4R5L5