You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2025/Day10/README.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,22 +10,22 @@ The first half of the problem was totally fine: we just had to find the combinat
10
10
11
11
However, Part 2 was, in my view, against the spirit of Advent of Code.
12
12
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.
14
14
15
-
The desired joltage becomes the vector **b**.
15
+
The desired joltage becomes the vector `b`.
16
16
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.
18
18
19
19
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.
20
20
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.
22
22
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.
24
24
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`.
26
26
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.
28
28
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.
30
30
31
31
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