
Notsobrute bruteforce:
This version is based on a simple test for tetrahedrality: if N = n.(n+1).(n+2) , n is the integer cube root of N , so that N gives n gives back the same N . (As one can check, n^3 <= N < (n+1)^3 so that n <= N^1/3 < n+1 .)
Now all tetrahedral number pairs are tried and their sum tested for tetrahedrality.
def T(n):
return n * (n + 1) * (n + 2)
def IsT(N):
return N == T(int(pow(N, 1. / 3.)))
for q in range(1, 1000):
for p in range(1, q):
if IsT(T(p) + T(q)):
print T(p) / 6, '+', T(q) / 6, '=', (T(p) + T(q)) / 6





Answer:
[120 ball pyramid] + [560 ball pyramid] = [680 ball pyramid]
def tetrahedral_number(n)
return n*(n+1)*(n+2)/6
end
#Build an array of tetrahedral numbers
t_nums = []
for i in (1..100)
t_nums << tetrahedral_number(i)
end
print "Tetrahedral Cannonball Stack Combinations:\n\n"
str = "ball pyramid"
#Find sums of tetrahedral numbers that are in the tetrahedral number set
for i in (0..99)
for j in (i..99)
if t_nums.include?(t_nums[i] + t_nums[j])
total = t_nums[i] + t_nums[j]
print "[#{t_nums[i]} #{str}] + ",
"[#{t_nums[j]} #{str}] = ",
"[#{total} #{str}] \n\n"
end
end
end





There is no specific answer without specifying a layer. The equation is simplified to be:
Y = (2X  1) + sum(2X  5)
where X is the level starting at 1 as the top and Y is the number of balls required to complete paramid.





And now a fast and efficient bruteforce method with additions only !
N= 1000
q= 1; qq= 1; qqq= 1
while q < N:
p= 1; pp= 1; ppp= 1
r= q; rr= qq; rrr= qqq
while p < q:
if ppp + qqq >= rrr:
if ppp + qqq == rrr:
print ppp, '+', qqq, '=', rrr
r+= 1; rr+= r; rrr+= rr
p+= 1; pp+= p; ppp+= pp
q+= 1; qq+= q; qqq+= qq
A few explanations:
Let iii denote the i th tetrahedral number (and ii the i th triangular number).
1) We try all (p, q) pairs such that 1<=p<q , for increasing q 's. As we go, we maintain the smallest index r such that ppp + qqq < rrr . It is easy to see that when we increment p , the condition can be invalidated; to restore it suffices to increment r (because iii is a superlinear function of i , rrr grows faster than ppp and adding 1 is enough).
2) We evaluate the tetrahedral numbers incrementally, i.e. by accumulating triangular numbers; and similarly, we evaluate the triangular numbers incrementally, by accumulating the integers.
To explore all solutions among the N first tetrahedral numbers, this algorithm takes O(N^2) operations, and O(1) space.
It is straightforward to adapt it to other superlinear series, such as the k th powers. Ever heard of X^k + Y^k = Z^k ?
modified 25Jan12 18:07pm.





It is also possible to precompute and store the tetrahedral numbers (need 2^1/3.N of them).
# Precompute 2^1/3.N tetrahedral numbers
T= []
q= 1; qq= 1; qqq= 1
while q < 1.26 * N:
T.append(qqq)
q+= 1; qq+= q; qqq+= qq
# Find all tetrahedral triplets
for q in range(1, N):
r= q
for p in range(1, q):
if T[p] + T[q] >= T[r]:
if T[p] + T[q] == T[r]:
print T[p], '+', T[q], '=', T[r]
r+= 1





I used a spreadsheet constructed as follows:
A1 = 2
A2 = 1
B1 = =IF(B1=1,A1+1,A1)
B2 = =IF(B1=1,A21,B11)
Then I dragged B1 and B2 downward to create a list of all the combinations of all the base sizes I wanted to examine. In my case, I chose to stop at line 2016 with column A at 64 and column B at 1.
C1 = =A1*(A1+1)*(A1+3)/6
I dragged C1 to D1.
E1 = =C1+D1
I dragged C1, D1 and E1 to line 2016.
I looked at the line that started with 64 and 63 to determine the maximum sum I could generate from the data I was using. Then I extended the table as follows:
A2017 = 1
E2017 = =A2017*(A2017+1)*(A2017+3)/6
I dragged A2017 through E2017 down until the entry in column E was as large as possible but still less than or equal to the largest sum in the upper part of the table. I added column F with 1's in the upper portion of the table and 0's in the lower portion of the table to distinguish the two types of entries.
I copied just the values from the table to a new sheet. I sorted the new table using column E as the primary key and column F as the secondary key.
I added conditional formatting to column E from row 2 down to change the background color of each cell to red if its value was the same as that of the cell above it. When I realized that my red cells included both cases where there were two sets of two differentsized tetrahedra that contained the same number of cannonballs and the desired cases where the cannonballs from two differentsized tetrahedra can be combined to make a larger tetrahedron, I added another column that contained 1 on the same condition that colored the red cells and 0 when those cells would be while. I then conditionally colored this column from row 2 down so that it was green if the row above contained a zero in column F. I did it this way because I couldn't create a more complex condition with the existing conditional coloring mechanism.
The answers that others have posted have already covered the three solutions that I found this way. The question answered by the red cells is interesting in and of itself. It leads to other questions such as: "Are there any numbers of cannonballs that can be stacked into two tetrahedra more than two ways?" and "Are there any cannonball tetrahedra that can be decompsed into two tetrahedra two or more ways?"
Questions of this type remind me of Goldbach's Conjecture that every even number greater than 2 can be expressed as the sum of two odd primes. That was the subject of one of the first programs I wrote in 1961. The conjecture has never been proven or disproven.





Funny, the Goldbach Conjecture is the first problem listed here. Seems like a fun problem to explore in one's free time.





Lots of effort has been spent on this problem by many people over a very long time. Look for it on Wikipedia to get an idea of how difficult a problem it is and how much computer time has been devoted to checking the conjecture over a very large range of numbers.





Oh I'm sure that's true. While it would be fun to explore the problem, I suspect it is all but impossible to solve.





I had a recent project that required a progress / status bar to be displayed but there was a restriction that there could only be zero, one or two images and the system that displayed them could only show them at their real width (no scaling). The progress bar had to work for all values from 0 to 100.
The simplest solution was to create 101 icons (one for each possible value) but I wanted to minimise the pool of icons (as I had to create them and there were four different colours so 101 would instantly grow to 404). Starting with Goldbach's Conjecture, I discovered that the only numbers that I couldn't create as the sum of two primes in the range 1 to 100 were 27, 51, 57, 65, 77 and 95. (This is consistent with Goldbach's Conjecture as these are all odd numbers and any odd number can be represented as an even number + 1 and it is even numbers that his conjecture say can be the sum of only two primes).
The answer was to cheat and invent a new type of number! I've called it a pseudo prime number.
The following is a quote from the actual source code comments:
REM {
The relative proportions are shown as a series of adjacent icons. A column can contain a maximum
of 10 icons. As the left and right ends of the image are icons, this leaves a maximum of 8 icons for
the values to be displayed. As there are (up to) four coloured bars per icon, each colour can be
represented as either a single icon or two adjacent icons (4 * 2 = 8).
This formula uses Goldbach's conjecture (1742) (modified) that any even number can be represented
as the sum of (up to) two prime numbers and any odd number can be represented as the sum of (up to)
three prime numbers (this is a direct corollary as if you can create any even number from 2 primes, just
adding 1 will produce the next odd number). Note: This treats 1 as a prime number.
With the sneaky addition of '4' as a pseudo prime number, we can generate all of the numbers from 1 to
102 with only single numbers or a sum of two numbers. We do not even need the prime numbers 41, 71
or 89.
So, actual icon widths used are: (total 26)
1, 2, 3, 4, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 43, 47, 53, 59, 61, 67, 73, 79, 83, 87, 91, 97
};
And the sums for 1 to 102 are:
1
2
3, 4
5, 3+3
7, 4+4, 7+2, 5+5
11, 7+5
13, 7+7, 13+2, 11+5
17, 11+7
19, 13+7, 19+2, 11+11
23, 13+11, 23+2, 13+13, 23+4, 17+11
29, 17+13
31, 19+13, 31+2, 17+17, 31+4, 19+17
37, 19+19, 37+2, 23+17
37+4, 23+19
43, 31+13, 43+2, 23+23
47, 41+7, 47+2, 31+19, 47+4, 29+23
53, 37+17, 53+2, 37+19, 53+4, 29+29
59, 31+29
61, 31+31, 61+2, 47+1, 61+4, 37+29
67, 37+31, 67+2, 47+23
67+4, 43+29
73, 37+37, 73+2, 47+29, 73+4, 47+31
79, 43+37, 79+2, 71+11
83, 71+13, 83+2, 43+43
87, 71+17
87+2, 47+43
91, 61+31, 91+2, 47+47, 91+4, 53+43
97, 61+37, 97+2, 53+47, 97+4, 59+43
modified 26Jan12 6:40am.





Mine's challenged at the moment.
Give me a written answer: "What is the locus of points equidistant from points A and B, which are six inches apart, and also five inches away from point A?"
Impress me cpians
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





It's the two points at which the circles of radius 5 inches centered at A and B intersect





How the hell did you do that?
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





Well, 5 inches from A means it's on the circle aroundA. Equidistant from B means it is 5 inches from B which describes a circle around B.
So the places the two circles intersect specify the two points satisfying yr requirements.





that's the trick (or the nugget)  noting to draw a circle around b.
missed that, and I still do.
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





You actually don't need to.
All points equidistant fromA and B form a straight line perpendicular to the line joining A and B  and meet that line 3 inches from both A and B
All points 5 inches from A form a circle around A radius 5.
Where the circle crosses the line ...





in the event you are humor impaired.
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





Are you implying your post was in some way humorous?





No, just covering my consternation at your immediate answer. I was a bit shocked and did not want you to take offense.
I'm still sketching on my white board!
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





and I think I just got munged by the posting s/w.
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





did you google?
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





No  its very basic geometry! And what would you google?
Also, as the circles are the same size, and we know the two points are 6 apart, we deduce that a triangle formed from A to the point of intersection of the circles to the line between A and B must meet that line 3 inches from A (and so also 3 inches from B)
So we have a right angled triangle, with one side of 3, one side of 5  so we know the third side is 4 due, as has been mentioned, to the squaw on the hipootamus being the sum of the sqaws on the other two hides.





You'd be surprised by how many direct answers are available when the text matches exactly.
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759





I was (and am) on my iPhone, so copy and paste is Too much of a pitA to use!





if A(3,0) and B(3,0), then the solution is C(0,4) and D(0,4), that's Pete A'Goras for you.




