Search

 
Problem Description
The city fathers recently decided that the square pyramidal stack of civil war cannonballs in front of the courthouse was a
hazard to the kiddies health. But it would be OK if the
cannonballs were laid in some arrangement flat on the ground.
By a miraculous coincidence, when the stack was disassembled, they could be
arranged to form a perfect square!
How many cannonballs were in the stack?
Background & Techniques
Here is beginner's program that can be solved
with less than 20 lines of code. The top layer of square pyramid
has one ball, the second layer has 4, the 3^{rd} layer, 9 and
the n^{th} layer contains n^{2} balls. We'll start adding up the
squares of consecutive integers until we find a sum that is a perfect
square. Testing numbers up to 100 should plenty be far enough to
find the solution.
Here's the essential Delphi code:
procedure TForm1.SolveBtnClick(Sender: TObject);
var i,sum,n:integer;
begin
sum:=1;
for i:= 2 to 100 do
{for a bunch of numbers}
begin
sum:=sum+i*i;
{sum the squares}
n:=trunc(sqrt(sum));
{get integer part of square root of the sum}
if n*n=sum then
{If sum was a perfect square,
we're done!}
begin
{Show "solved!" message here}
break; { and stop the loop}
end;
end;
end;
Square pyramids are one type of pentahedron
(five sided figures).
I couldn't resist adding 3D graphics
of the cannonballpiles as they are generated. 3D
graphics are too complicated for inclusion in a beginner's
program, so I cheated a little like this:
 I used a 3D graphics program to create a square
pyramid, rotated it until I like the looks of it and then copied
down the coordinates of the 5 corners. (The graphics program
used is a freeware Delphi program from Earl Glynn's 3D
Lab page. I modified Earl's cube figure to create a
square pyramid. ) 
 I scaled these points to fit nicely in the
image area using a test version of the program to actually draw the 8
edge lines. 
 I used the coordinates of these scaled points to
calculate x and y offset values in three categories:
 between layers in a stack (move left 6.46 pixels
and up
10.5 pixels for the lower left corner of each layer); 
 between rows of balls within a layer, (move left 2.5
pixels and up 6.5 pixels for leftmost ball in each row); and 
 between balls within a row (move left 11 and down 1.3
pixels for each ball). 

You'll find these constant values
in the drawing code parts of program version 2 included here.
 Since we are looking down slightly at the
stack, balls are drawn layer by layer from bottom to top, and from back to front
within each layer so
that higher, closer balls hide lower, more distant ones. 
Running/Exploring the Program
Suggestions for Further Explorations

Square
pyramidal numbers, the number of cannonballs in each stack, form the
series 1,5,14,30, 55, etc. Here's a link to a Wolfram
mathworld page describing some of the characteristics of this
series. 

The
problem presented here was based on an article in Martin Gardner's
The Colossal Book of Mathematics. As unlikely as
it seems, he says that the solution found by this program is the
only solution. It is apparently also true that the
proofs are not simple. I'd like to see the simplest of
them anyway. 

Square
pyramidal numbers (square pyramidal stacks) , along with tetrahedral
numbers (triangular pyramidal stacks), square numbers (layers of the square
pyramids) and triangular numbers (layers of the triangular stacks) have some
interesting relationships. For example, every
square
number is the sum of two consecutive triangular numbers and every
pyramidal number is the sum of two consecutive tetrahedral numbers. We have just found the only
pyramidal
number that is square. There are only four triangular numbers that are
also pyramidal (1, 55, 91, and one more big one). What
is it? A Google search on any of the bold terms above will give you
lots of sites to investigate in addition to those referenced here. 

There
are four other pairs of series
where the existence of common elements wants investigation (TriangularTetrahedral, Triangular Square, TetrahedralSquare,
TetrahedralPyramidal). 

AT&T's
great integer sequence site! 
Original: May 10, 2002 
Modified: May 18, 2009

