{A tetrahedron (triangular pyramid) has
1,3,6,10, etc in successive layers. A two layer
tetrahedron has 4 marbles, a perfect square. What is
the next larger with a total that is a perfect square?}
.
{generated code snipped here}.
.
.
procedure TForm1.SolveBtnClick(Sender: TObject);
{User clicked solve button}
{pretty much self commenting - isn't Delphi great?}
const maxmarbles=1000;
var {the 4 variables}
PyramidNbr :integer; {also nbr of marbles on a side}
layer :integer; {nbr of marbles in layer}
total :integer; {total in pyramid}
root :integer; {square root of total}
begin
layer:=0;
total:=0;
PyramidNbr:=0;
repeat
inc(PyramidNbr);
layer:=layer+PyramidNbr;
total:=total+layer;
root:=trunc(sqrt(total));
until ((PyramidNbr>3) and (root*root=total)) or (PyramidNbr>maxMarbles);
If root*root=total
then showmessage ('Side '+inttostr(PyramidNbr)
+', Layer '+ inttostr(layer)
+', Total '+inttostr(total)
+', Sqrt(Total) '+inttostr(root))
else Showmessage('No solutions with sides less than '+inttostr(maxmarbles));
end;
end.