Skip to content

Commit 2412864

Browse files
committed
readme
1 parent efc8110 commit 2412864

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

2025/Day10/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ The first half of the problem was totally fine: we just had to find the combinat
1010

1111
However, Part 2 was, in my view, against the spirit of Advent of Code.
1212

13-
It’s clearly a linear algebra problem. The buttons form the **matrix A**. Each button gets a column in **A** with zeros and ones corresponding to the bits of the button.
13+
It’s clearly a linear algebra problem. The buttons form the matrix `A`. Each button gets a column in `A` with zeros and ones corresponding to the bits of the button.
1414

15-
The desired joltage becomes the vector **b**.
15+
The desired joltage becomes the vector `b`.
1616

17-
Then one needs to solve **Ax = b** such that the components of **x** are non-negative integers and **Σ xᵢ** is minimal.
17+
Then one needs to solve `Ax = b` such that the components of `x` are non-negative integers and `Σ xᵢ` is minimal.
1818

1919
This is a textbook integer linear programming problem, trivially solved by an ILP solver, or in [my case](solve.py) z3. But this is not how Advent of Code has worked in the last 10+ years, so I was hoping for some shortcut, maybe a special structure of the input, but no luck. This really seems to be the intended way.
2020

21-
I did find another path, though, which is not that good-looking. One can notice that **A** is almost always full rank, and the kernel space has at most 2–3 dimensions.
21+
I did find another path, though, which is not that good-looking. One can notice that `A` is almost always full rank, and the kernel space has at most 2–3 dimensions.
2222

23-
This means we can solve the equation using Gaussian elimination, which will give us a solution with the columns in the kernel set to 0. There is no guarantee that the solution is integer, or that all xᵢ are non-negative, though.
23+
This means we can solve the equation using Gaussian elimination, which will give us a solution with the columns in the kernel set to 0. There is no guarantee that the solution is integer, or that all `xᵢ` are non-negative, though.
2424

25-
But once the columns in the base and the kernel are identified, we form a square matrix **B** and move the remaining columns to **K**, then deal with **Bx = b − Ky**.
25+
But once the columns in the base and the kernel are identified, we form a square matrix `B` and move the remaining columns to `K`, then deal with `Bx = b − Ky`.
2626

27-
Say that **K** has 3 columns. Now we can start brute-forcing by setting the values in **y** to some low integers: [1,0,0], [0,1,0], [0,0,1], then [1,1,0], [1,0,1], [0,1,1], [2,0,0], [0,2,0], [0,0,2], slowly increasing the sum of the values and solving for each combination.
27+
Say that **K** has 3 columns. Now we can start brute-forcing by setting the values in **y** to some low integers: `[1,0,0]`, `[0,1,0]`, `[0,0,1]`, then `[1,1,0]`, `[1,0,1]`, `[0,1,1]`, `[2,0,0]`, `[0,2,0]`, `[0,0,2]`, slowly increasing the sum of the values and solving for each combination.
2828

29-
This way we eventually get a feasible solution for the original problem, say with the total button-press count equal to 100 or so. Then it’s enough to continue the above iteration while the sum of yᵢ is ≤ 100. That gives us a termination condition. During the search we might run into better solutions, which further lowers the upper bound.
29+
This way we eventually get a feasible solution for the original problem, say with the total button-press count equal to 100 or so. Then it’s enough to continue the above iteration while the sum of `yᵢ` is ≤ 100. That gives us a termination condition. During the search we might run into better solutions, which further lowers the upper bound.
3030

3131
I [prototyped this idea](gauss.py) in Python with ChatGPT. I think, if anything, this could be ported to C#, but I don’t feel the urge. Although it uses first principles that one could potentially implement, it’s a much slower solution than the one using z3.

0 commit comments

Comments
 (0)