It seems the cleanest way to get what we want is to generate the solution up front.
NR65N5IQMKRXSPU5I65CRG65UE6JTMEMMSLQUFVZ5WBFPBJFO25AC
solve = function()
print('solve')
-- copy the slots we have
local c = Char.col_totals
local d = Char.data
Solution = {
col_totals = {c[1], c[2]},
data = {
{d[1][1], d[1][2] },
{ },
}
}
-- fill out the remaining data
Solution.data[2][1] = c[1] - d[1][1]
Solution.data[2][2] = c[2] - d[1][2]
d = Solution.data
Solution.row_totals = {
d[1][1] + d[1][2],
d[2][1] + d[2][2],
}
end
g.data[1][1] = math.random(1,9)
local d11 = g.data[1][1]
g.row_totals[1] = math.random(d11+1,10)
g.col_totals[1] = math.random(d11+1,10)
g.data[1][2] = g.row_totals[1] - d11
g.data[2][1] = g.col_totals[1]-d11
g.row_totals[2] = math.random(g.data[1][2]+1,10)
g.col_totals[2] = math.random(g.data[2][1]+1,10)
g.data[2][2] = g.col_totals[2]-g.data[2][1]
Solution = g