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 havelocal c = Char.col_totalslocal d = Char.dataSolution = {col_totals = {c[1], c[2]},data = {{d[1][1], d[1][2] },{ },}}-- fill out the remaining dataSolution.data[2][1] = c[1] - d[1][1]Solution.data[2][2] = c[2] - d[1][2]d = Solution.dataSolution.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] - d11g.data[2][1] = g.col_totals[1]-d11g.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