Search
As of October, 2016, Embarcadero is offering a free release
of Delphi (Delphi
10.1 Berlin Starter Edition ). There
are a few restrictions, but it is a welcome step toward making
more programmers aware of the joys of Delphi. They do say
"Offer may be withdrawn at any time", so don't delay if you want
to check it out. Please use the
feedback
link to let me know if the link stops working.
Support DFF  Shop
If you shop at Amazon anyway, consider using
this link. We receive a few cents from each purchase.
Thanks.
Support DFF  Donate
If you benefit from the website, in terms of
knowledge, entertainment value, or something otherwise useful,
consider making a donation via PayPal to help defray the
costs. (No PayPal account necessary to donate via credit
card.) Transaction is secure.
Contact
Feedback:
Send an
email with your comments about this program (or anything else).

 
Problem Description
Put 3 marbles in a triangle and place a 4th marble on
top. You have just built a triangular based pyramid, also
called a tetrahedron. If you started with 6 marbles and placed a
second layer of 3 and then one on top, you have another tetrahedron with 3 layers and
10 marbles. The two layer tetrahedron contains 4 marbles, a
perfect square(4=2^{2}). Can you find the next tetrahedron
whose total number of marbles is a perfect square?
Background & Techniques
Only about 10 lines of code in this one. Starting with a one
marble pyramid, we'll just generate the total for each pyramid from the previous
one. And stop when the square root of the total is an integer.
I put an upper limit of 1000 marbles per side, just in
case there weren't any small solutions. We don't want the program to loop
forever. Notice that each layer contains the number of marbles in
the previous layer plus the layer number additional. And the total is just
the previous total plus the number in this layer.
Tetrahedron # 
Marbles in bottom layer 
Total marbles 
1 
1 
1 
2 
3 
4 
3 
6 
10 
4 
10 
20 
5 
15 
35 
Running/Exploring the Program
Suggestions for Further Explorations

It turns out that there are names for each of the numbers we worked with in
this program. The number of marbles in each layer are triangular
numbers. And the total number of marbles in each pyramid is a tetrahedral
number. The solution found here is the largest
one. And, as you might suspect, there are algorithms to
compute the millionth tetrahedral number without computing the first
999,999. For more information, check this excellent site: http://mathworld.wolfram.com/TetrahedralNumber.html 

Triangular
numbers have other interesting properties. For
example

The sum of
any two consecutive triangular numbers is the square of an integer! 

The square
of the Nth triangular number minus the square of its predecessor is N^{
}cubed! 

The
Nth triangular number is also the number of ways we can select 2
objects from N+1, ignoring order (these are called combinations).
For example, the 3rd triangular number from the table above is 6.
and there are exactly 6 combinations for 2 of 4 objects. See Permutes2
program for more discussion of combinations. 

