Skip to content

Commit ace7352

Browse files
committed
fix: typing
1 parent 9be1533 commit ace7352

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ repos:
77
- id: ruff-format
88

99
- repo: https://github.com/pre-commit/mirrors-mypy
10-
rev: v1.8.0
10+
rev: v1.18.2
1111
hooks:
1212
- id: mypy
13+
args: ["--config-file=pyproject.toml"]
1314
additional_dependencies:
14-
["types-requests>=2.32.0", "types-beautifulsoup4>=4.12.0"]
15+
- "numpy"
16+
- "scipy>=1.16.3"
17+
- "scipy-stubs>=1.16.3.3"
18+
- "loguru"
19+
- "loguru-mypy"
20+
- "rustworkx>=0.17.1"
21+
- "types-requests>=2.32.0"
22+
- "types-beautifulsoup4>=4.12.0"
1523

1624
- repo: https://github.com/pre-commit/pre-commit-hooks
1725
rev: v4.5.0

_2025/solutions/day10.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
from collections import deque
1515
import math
1616
import re
17-
from typing import ClassVar
17+
from typing import ClassVar, cast
1818

19-
from numpy import transpose
19+
import numpy as np
20+
import numpy.typing as npt
2021
from scipy.optimize import linprog
2122

2223
from aoc.models.base import SolutionBase
@@ -193,16 +194,17 @@ def min_presses_for_machine(
193194
if any(t != 0 for t in target):
194195
err_msg = f"Unreachable target {target} with given buttons"
195196
raise ValueError(err_msg)
197+
196198
return 0
197199

198200
# Objective: minimize total button presses
199201
c = [1] * N
200202

201203
# Build equality constraints: sum(button_vectors * presses) = target
202-
A_eq = [self.button_to_vector(btn, num_jolt) for btn in buttons] # noqa: N806
203-
A_eq = transpose(A_eq) # noqa: N806
204-
b_eq = target
205-
integrality = [1] * N
204+
A_eq_list = [self.button_to_vector(btn, num_jolt) for btn in buttons] # noqa: N806
205+
A_eq: npt.NDArray[np.int_] = np.transpose(A_eq_list) # noqa: N806
206+
b_eq = np.array(target, dtype=int)
207+
integrality = np.ones(N, dtype=int)
206208

207209
res = linprog(
208210
c,
@@ -215,7 +217,9 @@ def min_presses_for_machine(
215217
err_msg = f"Unreachable target {target} with given buttons"
216218
raise ValueError(err_msg)
217219

218-
return int(math.ceil(sum(res.x)))
220+
x = cast(npt.NDArray[np.float64], res.x)
221+
total_presses = float(x.sum())
222+
return int(math.ceil(total_presses))
219223

220224
def part1(self, data: list[str]) -> int:
221225
"""Sum minimum button presses to match indicator lights for all machines.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dev = [
2222
"types-beautifulsoup4>=4.12.0,<5.0.0",
2323
"pytest>=8.3.4,<9",
2424
"pre-commit>=4.5.0",
25+
"loguru-mypy>=0.0.4",
2526
]
2627

2728
[tool.hatch.build.targets.sdist]
@@ -116,6 +117,8 @@ check_untyped_defs = true
116117
disallow_untyped_decorators = true
117118
no_implicit_optional = true
118119
strict_optional = true
120+
explicit_package_bases = true
121+
mypy_path = "."
119122

120123
[[tool.mypy.overrides]]
121124
module = [

uv.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)