Note: Not looking for the solution - just help on how to solve.
Here is the math puzzle:
Is there a mathematical model/method that I could employ to solve this?
Right now my only answer is to use Excel and trial-and-error my way to the solution.
Note: Not looking for the solution - just help on how to solve.
Here is the math puzzle:
Is there a mathematical model/method that I could employ to solve this?
Right now my only answer is to use Excel and trial-and-error my way to the solution.
First, divide everything by 20 to make your life easier. Then you are reduced to filling in your grid with 3 1's, 2 2's, 7 3's, and 3 4's so that every row, column and diagonal adds up to 10. (You still have a 0 where the black candy is, of course.)
Now, if you look mod 3 (i.e. consider remainders when dividing by 3), you'll see that in each row, column and diagonal, the number of 1's and 4's has to be exactly one more than the number of 2's. This is a pretty strong constraint since you have so few of these numbers available. You should also use the fact that the row and the column containing the 0 each must have one 4 and two 3's in it.
With this, I was able to find two different solutions via trial and error. I haven't bothered to determine if these are all the solutions, which I would guess is what the puzzle is asking for?
John M: If you request it, I'll post my two solutions in the comments if you're still stuck or want to check your solutions against mine.
You can set this up as a binary programming problem. Let $a_{i,j}$ be 1 if the candy at $(i,j)$ has 20 calories, 0 otherwise, and likewise for $b_{i,j}, c_{i,j}, d_{i,j}$ and 40, 60, and 80 calories, respectively. You then have three sets of equations:
Each candy can only be of one type (except the black candy, which is of no type): $ a_{i,j} + b_{i,j} + c_{i.j} + d_{i,j} = \begin{cases}1, & (i,j) \neq (4,3)\\ 0, &(i,j) = (4,3).\end{cases}$
The rows, columns, and diagonals must add up to the right number of calories: $\begin{align*} \sum_k (20a_{i,k} + 40b_{i,k} + 60c_{i,k} + 80d_{i,k}) &= 200\\ \sum_k (20a_{k,j} + 40b_{k,j} + 60c_{k,j} + 80d_{k,j}) &= 200\\ \sum_k (20a_{k,k} + 40b_{k,k} + 60c_{k,k} + 80d_{k,k}) &= 200\\ \sum_k (20a_{k,5-k} + 40b_{k,5-k} + 60c_{k,5-k} + 80d_{k,5-k}) &= 200.\end{align*}$
The total number of each type of candy is constrained: $\begin{align*} \sum a_{i,j} &= 3\\ \sum b_{i,j} &= 2\\ \sum c_{i,j} &= 7\\ \sum d_{i,j} &= 3.\end{align*}$
That's how I would model it, at least. Actually solving this linear program likely requires an NP-hard algorithm.