Fix linting.

This commit is contained in:
Mikael CAPELLE
2024-12-03 14:11:29 +01:00
parent cb0145baa2
commit acb767184e
49 changed files with 1160 additions and 353 deletions

View File

@@ -1,9 +1,9 @@
import sys
from typing import Literal
from typing import Any, Literal
import numpy as np
import parse
from tqdm import tqdm
import parse # pyright: ignore[reportMissingTypeStubs]
from numpy.typing import NDArray
Reagent = Literal["ore", "clay", "obsidian", "geode"]
REAGENTS: tuple[Reagent, ...] = (
@@ -35,7 +35,7 @@ class State:
self.robots = robots
self.reagents = reagents
def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
return (
isinstance(other, State)
and self.robots == other.robots
@@ -66,7 +66,7 @@ lines = sys.stdin.read().splitlines()
blueprints: list[dict[Reagent, IntOfReagent]] = []
for line in lines:
r = parse.parse(
r: list[int] = parse.parse( # type: ignore
"Blueprint {}: "
"Each ore robot costs {:d} ore. "
"Each clay robot costs {:d} ore. "
@@ -94,11 +94,12 @@ def run(blueprint: dict[Reagent, dict[Reagent, int]], max_time: int) -> int:
name: max(blueprint[r].get(name, 0) for r in REAGENTS) for name in REAGENTS
}
state_after_t: dict[int, set[State]] = {0: [State()]}
state_after_t: dict[int, set[State]] = {0: {State()}}
for t in range(1, max_time + 1):
# list of new states at the end of step t that we are going to prune later
states_for_t: set[State] = set()
robots_that_can_be_built: list[Reagent]
for state in state_after_t[t - 1]:
robots_that_can_be_built = [
@@ -132,7 +133,7 @@ def run(blueprint: dict[Reagent, dict[Reagent, int]], max_time: int) -> int:
for robot in robots_that_can_be_built:
robots = state.robots.copy()
robots[robot] += 1
reagents = {
reagents: IntOfReagent = {
reagent: state.reagents[reagent]
+ state.robots[reagent]
- blueprint[robot].get(reagent, 0)
@@ -151,7 +152,7 @@ def run(blueprint: dict[Reagent, dict[Reagent, int]], max_time: int) -> int:
]
)
to_keep = []
to_keep: list[NDArray[np.integer[Any]]] = []
while len(np_states) > 0:
first_dom = (np_states[1:] >= np_states[0]).all(axis=1).any()