better constrain possible problems
It seems the cleanest way to get what we want is to generate the solution up front.
This commit is contained in:
parent
7860ad4bf8
commit
d5f5859f02
|
@ -4,8 +4,6 @@ print(chord)
|
|||
new()
|
||||
elseif chord == '`' then
|
||||
if Draw == 'problem' then
|
||||
Draw = 'char'
|
||||
elseif Draw == 'char' then
|
||||
Draw = 'solution'
|
||||
elseif Draw == 'solution' then
|
||||
Draw = 'problem'
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
-- a set of numbers that uniquely characterizes a sum-grid instance.
|
||||
Char = {
|
||||
row_totals={0, 0},
|
||||
col_totals={0, 0},
|
||||
data={
|
||||
{0, 0},
|
||||
{0, 0},
|
||||
},
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
-- solution for the sum-grid problem defined by Char.
|
||||
Solution = {
|
||||
row_totals={0, 0},
|
||||
col_totals={0, 0},
|
||||
|
|
21
0020-solve
21
0020-solve
|
@ -1,21 +0,0 @@
|
|||
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
|
|
@ -1,14 +1,20 @@
|
|||
generate = function()
|
||||
-- a sum grid is fully characterized by 4 numbers
|
||||
Char = {
|
||||
local g = {
|
||||
col_totals = {'', ''},
|
||||
row_totals = {'', ''},
|
||||
data = {
|
||||
{ math.random(1,9), math.random(1,9) },
|
||||
{ '', ''},
|
||||
{'', ''},
|
||||
{'', ''},
|
||||
},
|
||||
row_totals = { '', '' },
|
||||
}
|
||||
Char.col_totals = {
|
||||
math.random(Char.data[1][1]+1,10),
|
||||
math.random(Char.data[1][2]+1,10)
|
||||
}
|
||||
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
|
||||
end
|
Loading…
Reference in New Issue