Had to brush up on my linear algebra, but here’s the continuation of my idea from before:
I will use the same example matrix as above.
The matrix above has 6 equations (rows) and 8 variables (columns k0 up to k7). We first need to reduce the matrix as much as possible and write it in row echelon form. This will not actually be in reduced row echelon form because there are some nasty ratios in the equations. For this purpose I used scipy.linalg.lu, but in Ada we’d need to do this ourselves or find a library. This gives us:
1 0 0 0 0 0 1 1 | 173
0 1 0 0 1 1 1 1 | 198
0 0 1 0 0 1 0 1 | 22
0 0 0 1 1 0 0 -1 | 28
0 0 0 0 1 0 -1 -1 | -153
0 0 0 0 0 0 3 1 | 487
We can see that columns for k5 and k7 do not have a row with a leading integer, so they can take any value. Conceptually, we can insert those equations manually to state k5 = x and k7 = y:
1 0 0 0 0 0 1 1 | 173
0 1 0 0 1 1 1 1 | 198
0 0 1 0 0 1 0 1 | 22
0 0 0 1 1 0 0 -1 | 28
0 0 0 0 1 0 -1 -1 | -153
0 0 0 0 0 1 0 0 | x <-- new row
0 0 0 0 0 0 3 1 | 487
0 0 0 0 0 0 0 1 | y <-- new row
Now we just need to find values for x and y such that A * presses = b where A is the non-augmented matrix and b is the augmented column. presses is the vector [k0, k1, k2 ... k7] and is given by back substitution using the values we pick for x and y.
matrix form equation simplified equation
k7 = y k7 = y
3*k6 + k7 = 487 k6 = (487 - y) / 3
k5 = x k5 = x
k4 - k6 - k7 = -153 k4 = k6 + y - 153
k3 + k4 - k7 = 28 k3 = 28 - k4 + y
k2 + k5 + k7 = 22 k2 = 22 - x - y
k1 + k4 + k5 + k6 + k7 = 198 k1 = 198 - k4 - x - k6 - y
k0 + k6 + k7 = 173 k0 = 173 - k6 - y
After back substitution, we can produce solutions by varying only two values instead of eight. This greatly reduces the search space.
There are two constraints that make this even easier: all values of k must be integers (no 0.5 button presses) and they must be >= 0 (no unpressing of buttons). Now we can generate a bunch of solutions trivially.
Here’s a direct translation of these equations to python:
import itertools
best = 1e9
for x, y in itertools.product(range(100), range(100)):
k = [0] * 8
k[7] = y
k[6] = (487 - y) / 3
k[5] = x
k[4] = k[6] + y - 153
k[3] = 28 - k[4] + y
k[2] = 22 - x - y
k[1] = 198 - k[4] - x - k[6] - y
k[0] = 173 - k[6] - y
if all(val.is_integer() and val >= 0 for val in k):
if sum(k) < best:
best = int(sum(k))
print(x,y,[int(val) for val in k],best)
Sure enough this generates an optimal solution:
x y presses sum(presses)
0 1 [10, 25, 21, 19, 10, 0, 162, 1] 248
0 4 [8, 21, 18, 20, 12, 0, 161, 4] 244
0 7 [6, 17, 15, 21, 14, 0, 160, 7] 240
0 10 [4, 13, 12, 22, 16, 0, 159, 10] 236
0 13 [2, 9, 9, 23, 18, 0, 158, 13] 232
0 16 [0, 5, 6, 24, 20, 0, 157, 16] 228
1 16 [0, 4, 5, 24, 20, 1, 157, 16] 227
2 16 [0, 3, 4, 24, 20, 2, 157, 16] 226
3 16 [0, 2, 3, 24, 20, 3, 157, 16] 225
4 16 [0, 1, 2, 24, 20, 4, 157, 16] 224
5 16 [0, 0, 1, 24, 20, 5, 157, 16] 223 <------ correct answer
There’s one last piece of the puzzle missing: how do we determine the upper bound on x and y? There’s probably a better way to do this, but one method is to look at the joltages that each button increments and pick the minimum of them. Pressing the button more times than that would go beyond the target joltage which makes the solution invalid. In practice the actual upper bound may be lower because pressing a second button can reduce the number of times you can press the first one. Maybe we can come up with another system of equations for that later. 
For reference here’s our input again:
(4,5) (0,5) (2,3) (1,3,5) (0,3,5) (0,2,3,5) (0,1,4) (0,2,4,5) {198,181,22,50,173,65}
^~~ k5 ~~ ^~~ k7 ~~
k5 (x) upper bound is min(198,22,50,65) = 22
k7 (y) upper bound is min(198,22,173,65) = 22
Add 1 to each bound to get the number of states we need to consider since we can leave a button at zero presses. Thus we can solve this specific example in (1+22)*(1+22) = 529 iterations.