The solution makes an upward run symbolically, though excluding Z. After that two blocks (1,1) and (3,1) being known yield a 2x2 linear system, from which X and Y are determined. Finally each block is revisited and printed.

;---------------------------------------------------------------------------GuiClose:;---------------------------------------------------------------------------GuiEscape:;---------------------------------------------------------------------------ButtonExit:;---------------------------------------------------------------------------; common actionExitApp

; mouse is over buttonsElseIf(CurrControl ="&Restart")SB_SetText("restart retaining the blue clues")ElseIf(CurrControl ="&Solve")SB_SetText("calculate solution")ElseIf(CurrControl ="&Check")SB_SetText("check if the entries are correct")ElseIf(CurrControl ="Cle&ar")SB_SetText("restart without the blue clues")ElseIf(CurrControl ="&New")SB_SetText("enter new numbers for the puzzle")ElseIf(CurrControl ="E&xit")SB_SetText("exit " AppName)

This solution is based upon algebraic necessities, namely that a solution exists when (top - 4(a+b))/7 is integral. It also highlights the type difference between floating point numbers and integers in C.

Treating relations between cells as if they were differential equations, and apply negative feedback to each cell at every iteration step. This is how field equations with boundary conditions are solved numerically. It is, of course, not the optimal solution for this particular task.

This solution follows the way the problem might be solved with pencil and paper. It shows a possible data representation of the problem, uses the computer to do some arithmetic, and displays intermediate and final results.

one should calculate all possible values that fit. That just means solving a linear system of equations. We use the first three variables as placeholders for X, Y and Z. Then we can produce the matrix of equations:

To solve the system, any linear algebra library will do (e.g hmatrix). For this example, we assume there are functions decompose for LR-decomposition, kernel to solve the homogenous system and solve to find a special solution for an imhomogenous system. Then

# set up trianglemy$rows=5;my@tri=map{[map{{x=>0,z=>0,v=>0,rhs=>undef}}1..$_]}1..$rows;$tri[0][0]{rhs}=151;$tri[2][0]{rhs}=40;$tri[4][0]{x}=1;$tri[4][1]{v}=11;$tri[4][2]{x}=1;$tri[4][2]{z}=1;$tri[4][3]{v}=4;$tri[4][4]{z}=1;

-- each cell in the pyramid is either an integer final value or an equation.-- initially the equations are strings, we substitute all with triplets of-- the form {k,x,z} ie k+l*x+m*z, and known values < last row become rules.

for r=5 to 1 by -1 do for c=1 to length(pyramid[r]) do object prc = pyramid[r][c], equ if prc="x" then prc = {0,1,0} -- ie one x elsif prc="y" then prc = {0,1,1} -- ie one x plus one z elsif prc="z" then prc = {0,0,1} -- ie one z else if prc="" or r<=4 then -- examples: x+11 is {0,1,0}+{11,0,0} -> {11,1,0}, -- 11+y is {11,0,0}+{0,1,1} -> {11,1,1}, -- 40=""+"" is {40,0,0}={22,2,1} ==> {18,2,1} equ = sq_add(pyramid[r+1][c],pyramid[r+1][c+1]) end if if prc="" then prc = equ else prc = {prc,0,0} if r<=4 then equ[1] = prc[1]-equ[1] rules = append(rules,equ) end if end if end if pyramid[r][c] = prc end forend for

Interestingly, this appears to match Python in that 40 is propagated up the tree, whereas Perl and Go appear to propagate 22+2x+z up, not that I can think of any case where that would make a difference.