Fix linting.
This commit is contained in:
@@ -56,7 +56,7 @@ def propagate(
|
||||
[() for _ in range(len(layout[0]))] for _ in range(len(layout))
|
||||
]
|
||||
|
||||
queue = [(start, direction)]
|
||||
queue: list[tuple[tuple[int, int], Direction]] = [(start, direction)]
|
||||
|
||||
while queue:
|
||||
(row, col), direction = queue.pop()
|
||||
|
@@ -114,11 +114,12 @@ for workflow_s in workflows_s.split("\n"):
|
||||
for block in block_s[:-1].split(","):
|
||||
check: Check
|
||||
if (i := block.find(":")) >= 0:
|
||||
check, target = (
|
||||
check = (
|
||||
cast(Category, block[0]),
|
||||
cast(Literal["<", ">"], block[1]),
|
||||
int(block[2:i]),
|
||||
), block[i + 1 :]
|
||||
)
|
||||
target = block[i + 1 :]
|
||||
else:
|
||||
check, target = None, block
|
||||
workflows[name].append((check, target))
|
||||
|
@@ -19,7 +19,7 @@ def _name(i: int) -> str:
|
||||
|
||||
|
||||
def build_supports(
|
||||
bricks: list[tuple[tuple[int, int, int], tuple[int, int, int]]]
|
||||
bricks: list[tuple[tuple[int, int, int], tuple[int, int, int]]],
|
||||
) -> tuple[dict[int, set[int]], dict[int, set[int]]]:
|
||||
# 1. compute locations where a brick of sand will land after falling by processing
|
||||
# them in sorted order of bottom z location
|
||||
|
@@ -2,24 +2,34 @@ import logging
|
||||
import os
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Literal, Sequence, TypeAlias, cast
|
||||
|
||||
VERBOSE = os.getenv("AOC_VERBOSE") == "True"
|
||||
logging.basicConfig(level=logging.INFO if VERBOSE else logging.WARNING)
|
||||
|
||||
Direction = {
|
||||
DirectionType: TypeAlias = Literal[">", "<", "^", "v", ".", "#"]
|
||||
|
||||
Direction: dict[DirectionType, tuple[int, int]] = {
|
||||
">": (0, +1),
|
||||
"<": (0, -1),
|
||||
"^": (-1, 0),
|
||||
"v": (+1, 0),
|
||||
}
|
||||
|
||||
Neighbors = {".": ((+1, 0), (-1, 0), (0, +1), (0, -1)), "#": ()} | {
|
||||
k: (v,) for k, v in Direction.items()
|
||||
}
|
||||
Neighbors = cast(
|
||||
"dict[DirectionType, tuple[tuple[int, int], ...]]",
|
||||
{
|
||||
".": ((+1, 0), (-1, 0), (0, +1), (0, -1)),
|
||||
"#": (),
|
||||
}
|
||||
| {k: (v,) for k, v in Direction.items()},
|
||||
)
|
||||
|
||||
|
||||
def neighbors(
|
||||
grid: list[str], node: tuple[int, int], ignore: set[tuple[int, int]] = set()
|
||||
grid: list[Sequence[DirectionType]],
|
||||
node: tuple[int, int],
|
||||
ignore: set[tuple[int, int]] = set(),
|
||||
):
|
||||
"""
|
||||
Compute neighbors of the given node, ignoring the given set of nodes and considering
|
||||
@@ -51,7 +61,7 @@ def neighbors(
|
||||
|
||||
|
||||
def reachable(
|
||||
grid: list[str], start: tuple[int, int], target: tuple[int, int]
|
||||
grid: list[Sequence[DirectionType]], start: tuple[int, int], target: tuple[int, int]
|
||||
) -> tuple[tuple[int, int], int]:
|
||||
"""
|
||||
Compute the next 'reachable' node in the grid, starting at the given node.
|
||||
@@ -75,7 +85,7 @@ def reachable(
|
||||
|
||||
|
||||
def compute_direct_links(
|
||||
grid: list[str], start: tuple[int, int], target: tuple[int, int]
|
||||
grid: list[Sequence[DirectionType]], start: tuple[int, int], target: tuple[int, int]
|
||||
) -> dict[tuple[int, int], list[tuple[tuple[int, int], int]]]:
|
||||
if start == target:
|
||||
return {}
|
||||
@@ -85,7 +95,7 @@ def compute_direct_links(
|
||||
i, j = neighbor
|
||||
di, dj = Direction[grid[i][j]]
|
||||
|
||||
reach, distance = reachable(lines, (i + di, j + dj), target)
|
||||
reach, distance = reachable(grid, (i + di, j + dj), target)
|
||||
direct[start].append((reach, distance + 2))
|
||||
|
||||
direct.update(compute_direct_links(grid, reach, target))
|
||||
@@ -124,7 +134,7 @@ def longest_path_length(
|
||||
return max_distance
|
||||
|
||||
|
||||
lines = sys.stdin.read().splitlines()
|
||||
lines = cast(list[Sequence[DirectionType]], sys.stdin.read().splitlines())
|
||||
n_rows, n_cols = len(lines), len(lines[0])
|
||||
start = (0, 1)
|
||||
target = (len(lines) - 1, len(lines[0]) - 2)
|
||||
|
Reference in New Issue
Block a user