Let $n$ be a positive integer where $n > 1$ and $n \neq 3$
I need a way to return all solutions of $2a + 4b + 5c + 6d = n$ where $a, b, c$, and $d$ are non-negative integers and $a + c$ is as small as possible so I can choose a random one.
This is a problem I have conceived myself but I believe it is solvable.
If $n$ is odd we must use 5 once because adding any number of 2's, 4's, and 6's results in an even number. In the odd cases after the subtraction of 5 we are always left with an even number. If $n$ is odd let $n_2=n-5$. If $n$ is even let $n_2=n$. We then can remove a random number of 6's ($d$). $d$ is between 0 and $\lfloor\frac{n_2}{6}\rfloor$. Let $n_3=n_2-6d$. $n_3$ must be even. If $n_3$ is of the form $4b+2$ then one 2 must be used and then the rest can be 4's. If $n_3$ is of the form $4b$ then the rest can be 4's. In conclusion $n$ can be one of four outcomes given that $d$ is randomized.
$6d+7+4b$
$6d+5+4b$
$6d+2+4b$
$6d+4b$