How can I optimally play/code a program to optimally play this maths game? I've been trying to make a program to optimally play this maths game for a few days now, but I cannot figure out a way to quantify how good a move is.
Everybody I have explained the game to has not understood it/misinterpreted it until I explained more, so I will be very thorough.
The objective of the game is to create two numbers whoms sum adds up as closely to a preknown goal as possible, you create these numbers by first drawing/generating a number from 0-9 and then placing the drawn number into a "slot" (look at the image!) these slots are place values for numbers.
One thing I should reiterate, you draw a number, place it in a slot and draw again. You cannot hold the numbers until you draw more, you must place it directly after drawing it.
So, how can I properly calculate the best possible place to put the drawn number, is it even possible? Thanks a lot for any insight.
Full example game
 A: This sounds like an interesting game! I am not a programmer, so I'll approach from a mostly mathematical perspective. I would kindly request that you could clarify 2 doubts I had about the rules that could really change the answer I give. I will call the full process of the game as described as a round.
So, are the number of slots fixed for all rounds (such that, for any target number, you always have to sum three digits numbers), or can they also change?
Also, can you draw the same number twice? (your example happens to be all six non equal digits, but could be a coincidence).

For now, I will take that the number of slots is fixed per round (I feel that it could be much more difficult to find an answer, if not impossible, otherwise), that you can draw a given number more than once (although not allowing repetition could make this a simpler problem) and also that zero is included.
I should mention that the rules feel really similar to Blackjack with some changes:

*

*You cannot go bust, no problem going over the target;

*You have greater control over the "card" drawn, similar to the ace, but not exactly equal;

*You must draw six "cards", no more and no less.

So, in that sense, I guess if you search how the Blackjack basic strategy came to be (https://wizardofodds.com/ has some wonderful explanations about it, including variants of the original game), you could maybe find a basic strategy for this game.

I would recommend that prior to attempting your actual problem, that at first glance seems intimidating, you attempt some simpler version of the game. If possible for that, then try applying what you learn to the "regular" version.
So, for exemple, lets pick the most basic case, that you only have two, one slot, numbers. You have no choice there, the sum will simply be random.
Therefore, lets see the two slot case. I will also assume that the player play with the hypothesis that any number other than the target is a loss (which should be clear why afterwards). You have that the target number can be, at most, $198=99+99$. Given $n\in\mathbb{N}$, such that $n\leqslant 198$, the first step should be to find all possible ways to sum to that number, that is:
$a,b\in\mathbb{N}$ such that $a+b=n$.
With no loss of generality, assume that $a\leqslant b$, giving us the set:
$N^0=\{(0,n),(1,n-1),\ldots,(\lfloor n/2\rfloor,\lceil n/2\rceil)\}\subset\mathbb{N}^2$
(The $N^i$ set being the possible factors of the sum to $n$, after the $i$-draw)
You could also call $N^0$ the set of all $v\in\mathbb{N}^2$ such that $\|v\|_1=n$
Now, unless $n<9$, all digits will be in one of the terms of $N^0$. So, for your first draw, you wish to position the number such that you can still find some $v\in N^0$, which will become $N^1$, and that the chosen $N^1$ has the biggest possible cardinality.
For exemple, with $n=50$, the set will be $N^0=\{(0,50),(1,49),\ldots,(25,25)\}$. If you draw $x_1>5$, you must place $x_1$ in the unit slot, otherwise you cannot get the target. If you draw $x_1=5$, you could place at any slot, but will be advantageous to place in the unit slot, for $N^1=\{(5,45),(15,35),(25,25)\}$, the reduced set of acceptable summations, opposed to $N^1=\{(0,50)\}$ if you place at the other slot.
The optimal strategy should be to apply this idea to fill all four slots. Note that even if you are able to arrive at a $N^3\neq\emptyset$, the fourth draw will depend on luck. If you assume at start a maximum distance to target $\delta\neq0$, you will have a bigger initial set $M^0=(N-\delta)^0\bigcup(N-(\delta-1))^0\bigcup\ldots\bigcup N^0\bigcup\ldots\bigcup(N+\delta)^0$, which should make easier to ensure your final result is acceptable.
Now, the best $\delta$ to choose could also be an interesting problem. To each fixed $\delta$, it indeed seems to be possible to arrive at an optimal play. Also, you could have $\delta$ changing as needed along the game (such as, starting with $\delta=0$ and increasing if at some point $N^i=\emptyset$), although I feel this should give a worse result than starting with a fixed $\delta>0$ (similar to the idea of the dealer in Blackjack always stopping at 17 rather than always trying to improve to 21). For the three slots variant in the question, I feel the same idea should apply, although you would have to check the cardinality of three sets, opposed to the two made here, and that those sets ought to be larger.
A good thing to check would be if the biggest set of summations is also the set with the most quantities of all digits. If not, that could be another approach for an optimal play, given the randomness.
