So I only took math up to high school level and a bit during uni, but I do code a lot and can figure out a lot of algorithms and formulas to get what I want, but this stumped me...
I never had to figure out a formula/algorithm that gives this specific answer I want, and I mostly try to solve it by trial and error manually, but I want to automate this process.
I have this formula: 9x + 5y + 3z = w
Being that x, y, and z must all be non-negative integers. I have the value of w, and I want to find the combination of x, y, and z that sum to the lowest number possible. So x + y + z needs to be the lowest number possible, while giving me the w result.
For example, if I want w = 30, I know that the best combination is x = 3, y = 0, z = 1, which results in 9*3 + 5*0 + 3*1 = 30
This has a x + y + z = 4. I know other possible combinations will have a higher sum. Another possible combination is simply x = 0, y = 6, z = 0, but that sums up to x + y + z = 6.
This is basically the context:
I have the option of 3 actions, each gives a different amount of points. One gives 3 points, one gives 5 points, and the last gives 9 points. I can only do 1 action every few hours, and I want to optimize the time it takes to get to a certain amount of points. Sometimes I can go OVER the amount of points I need (like I need at least 40 points, but if 45 is quicker, I can go over to 45), but sometimes I need the exact amount (I need exactly 40 points, so I need to do 3x the 9 points action, 1x the 3 points action, and 2x the 5 points action), so this is another var I could take into account...
I do accept brute-force coding! I just want to make it more optimized as to at least finding the different combinations that give me that amount of points.
I also don't know about math terms and what kind of equation this is, so I'll leave this untagged and ask for help to tag it. I think it is a linear equation, but I am not sure...
Brute force approach pseudocode:
First take an array $S=(0,0,0)$.
Check if $(x,y,z)=S$ satisfies the equation.
Declare an array $B$ as the set of all 3 digit non-zero binary numbers, ordered in ascending order of digital sum ($001, 010, 100, 011, 101, 110, 111$)
Now for each 3 digit binary number in $B$, do:
Split $b$ into a tuple $T$; like $010$ becomes $(0,1,0)$
Check if $(x,y,z)=S+T$ satisfies your equation
End for loop
Update $S$ by $S=S+(1,1,1)$ and repeat from the start of the for loop
Edit: I think that this method can quite easily be extended for more than 3 parameters