I got stuck solving the following problem:
Table[Table[
Table[
g1Size = x; g2Size = y;
vals =
FindInstance[(a1 - a2) - (b1 - b2) == z && a1 + b1 == g1Size &&
a2 + b2 == g2Size && a1 + a2 == g1Size && b1 + b2 == g2Size &&
a1 > 0 && a2 > 0 && b1 > 0 && b2 > 0, {a1, a2, b1, b2},
Integers, 3];
aa1 = a1 /. vals; aa2 = a2 /. vals; bb1 = b1 /. vals;
bb2 = b2 /. vals;
{g1Size, g2Size, z, Flatten@{aa1, aa2, bb1, bb2}}
, {z, 0, 10}], {x, 1, 10}], {y, 1, 10}]
I want to loop through different values of g1Size, g2Size and z and find the first solution to the system of equations. As soon as a solution for a combination of g1Size,g2size and z was found, I want to extract the values for a1,a2,b1,b2 and continue with the next loop. In other words, only print the values when vals is not empty and then stop the z-loop and switch to the next values of x and y.
But my output is like this:
{{{{1, 1, 0, {a1, a2, b1, b2}}, {1, 1, 1, {a1, a2, b1, b2}}, {1, 1,
2, {a1, a2, b1, b2}}, {1, 1, 3, {a1, a2, b1, b2}}, {1, 1,
4, {a1, a2, b1, b2}}, {1, 1, 5, {a1, a2, b1, b2}}, {1, 1,
6, {a1, a2, b1, b2}}, {1, 1, 7, {a1, a2, b1, b2}}, {1, 1,
8, {a1, a2, b1, b2}}, {1, 1, 9, {a1, a2, b1, b2}}, {1, 1,
10, {a1, a2, b1, b2}}}
plotting the names for a1,a2,b1,b2 when no solution was found.
My mathematica coding is a bit rust and this code seems far from elegant. And I hope it is clear what I mean :).
FindInstance
, when you say that you want to switch to the next value ofz
"As soon as a solution for a combination of g1Size,g2size and z was found (...)"? Do you want 3 instances for each{g1Size, g2Size, z}
, or just 1? $\endgroup$