IQ / Programming Quiz (Cannon-Ball Stacks)
-
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
Well, using a bit of python:
def pyr(l):
if l==0:
return 0
elif l==1:
return 1
else:
return pyr(l-1)+l*(l+1)/2#then we brute-force
a=[pyr(i) for i in range(100)][1:]
b=[(i,j,k) for i in a
for j in a
for k in a
if (i!=j and i+j==k)]
if len(b)>0:
print b[0]Running the above yields the result as
(120, 560, 680)
as others have already pointed out... (Edit: changed the type from general to Answer)
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)
-
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
A Python script can do. Grow a list of tetrahedral numers; for every new number, try and find a number in the list such that when subtracted from the new number, it gives another number in the list. (This way you make sure that for every new number the two terms of the decomposition are already in the list.)
# Start with an empty list
List= {}
n= 1while n > 0:
# Try the next tetrahedral number
r= n * (n + 1) * (n + 2) / 6# Try every number in the list for p in List: # Lookup the difference between the new number and the current one q= r - p if p != q and q in List: print p, '+', q, '=', r # Flag as found n= -1 break # Not found, extend the list List\[r\]= None n+= 1
For efficiency of the search, the list is implemented as a dictionnary. Yields:
560 + 120 = 680
-
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
Haskell answer:
layers = scanl1 (+) [1..]
sizes = scanl1 (+) layers
combinedSizes = [(s1, s2, s1 + s2) | s1 <- sizes, s2 <- takeWhile (< s1) sizes]
newPyramids = filter combinesToPyramid combinedSizes
where combinesToPyramid (s1, s2, sum) = sum `elem` (takeWhile (sum >=) sizes)answer = head newPyramids
-------- SPOILER ------------ this gives the answer as "(560, 120, 680)", (if you load it up in GHCI and type "answer"). If you want the n first solutions, just type "take n newPyramids":
take 3 newPyramids
[(560,120,680),(27720,1540,29260),(29260,4960,34220)] -
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
Brute force:
def T(n):
return n * (n + 1) * (n + 2) / 6r= 1
while True:
q= 1
while q < r:
p= 1
while T(p) + T(q) < T(r):
p+= 1
if T(p) + T(q) == T(r):
print T(p), '+', T(q), '=', T(r)
q+= 1
r+= 1Yields:
10 + 10 = 20
560 + 120 = 680
120 + 560 = 680
27720 + 1540 = 29260
1540 + 27720 = 29260
29260 + 4960 = 34220
4960 + 29260 = 34220
59640 + 10660 = 70300
10660 + 59640 = 70300
182104 + 39711 = 221815
39711 + 182104 = 221815
... -
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
Even bruter force:
def T(n):
return n * (n + 1) * (n + 2) / 6for r in range (1, 1000):
for q in range(1, r):
for p in range(1, q):
if T(p) + T(q) == T(r):
print T(p), '+', T(q), '=', T(r)Yields:
120 + 560 = 680
1540 + 27720 = 29260
4960 + 29260 = 34220
10660 + 59640 = 70300
39711 + 182104 = 221815
102340 + 125580 = 227920
7140 + 280840 = 287980
19600 + 447580 = 467180
... -
AspDotNetDev wrote:
what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid?
A couple of points: - You can't make a tetrahedron with 10 cannon balls; you need 11. - You'd have to define "large".
I wanna be a eunuchs developer! Pass me a bread knife!
Sorry, 6 on the bottom, 3 next then 1 = total 10 for a 3x3x3 pyramid!
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
-
A=20, B=54, C=55 or B=54, A=20, C=55 used two recurisve functions and iteration (lazy mans search).
I=I.am()?Code(I):0/0;
Nope, 20 + 54 is not 55.
-
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
Maybe not the most elegant solution but might possibly be the fastest way to come up with the answer!: 1 Using Excel I created 3 columns: column 1 being a linear sequence (1,2,3 ....100); column 2 representing each layer (B1=1,B2=A1+A2); the third representing the pyramid (C1=1,C2=B1+B2) 2 I pasted these into an Access table 3 I cross joined the table to itself and added the two columns 3 4 I inner joined the query to the table on sum = column 3 Answer 120 (8 layers) + 560 (14 layers) = 680 (15 layers)
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
-
There is a single numeric answer.
got one, just by accident :) 560 + 120 = 680, which are an 8-layered and a 14-layered pyramid combined to a 15-layered pyramid. still thinking of an smart search or algebraic solution tho [edit for some code] clear clc lines(0) n = 30 m(1) = 1 k(1) = 1 for i = 1:n m(i+1) = m(i) + 1 + (i) k(i+1) = k(i) + m(i+1) end [/edit]
-
Background
I'm reading "The Mammoth Book of IQ Puzzles". It contains, as you may have guessed, a bunch of IQ puzzles. I just solved one of them and thought I'd write the problem down here so you would all have a chance to solve it too. It is called "Cannon-Ball Stacks". In finding the answer, reference materials, books, calculators, and computers are allowed. Since computers are allowed, programs can be created to get the solution.
Cannon-Ball Stacks
A park ranger has stacked cannon-balls in two tetrahedral pyramids for display at Gettysburg. He later decides to combine the cannon-balls in both of the pyramids in order to create one large pyramid. The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids).
[10 cannon-ball pyramid] + [10 cannon-ball pyramid] = [20 cannon-ball pyramid]
If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? Difficulty: 4 out of 5.
AspDotNetDev's Extra Rules
Explain how you arrived at the solution. If you create a program to help you solve the problem, paste that in your message. I will reply to this message with the answer in a hidden <span> tag. Don't cheat by looking first though! I will post tomorrow how I arrived at my solution (which may be incorrect, as the book doesn't list what the correct answer is). Points will be awarded for: elegance, quickness, humor, and correcting others (in no particular order). Good luck!
Wow such complicated answers.... the answer is 4. The question is If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? ... but the thing is, there are still only 20 cannonballs to use to build the pyramid and he never said you had to use all the cannonballs. It asks the MINIMUM... which is 3 on the bottom + 1 on top.
-
Wow such complicated answers.... the answer is 4. The question is If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? ... but the thing is, there are still only 20 cannonballs to use to build the pyramid and he never said you had to use all the cannonballs. It asks the MINIMUM... which is 3 on the bottom + 1 on top.
How do 3 cannonballs make a tetrahedral pyramid? :P
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
-
How do 3 cannonballs make a tetrahedral pyramid? :P
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
I didn't say 3 I said 4 :P
-
I didn't say 3 I said 4 :P
... but the source has to be two tetrahedral pyramids ...
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
-
... but the source has to be two tetrahedral pyramids ...
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
but not all of them: The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids). That's an assumption, not a requirement :)
-
but not all of them: The smallest number of cannon-balls he can have if the two pyramids are the same size is twenty (assuming he uses every cannon-ball in both pyramids). That's an assumption, not a requirement :)
Using that logic I think that your answer might be one :cool:
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
-
Using that logic I think that your answer might be one :cool:
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
Otherwise you would have to form two different sized pyramids who could form one larger pyramid without any left overs. That would require a Calculus 1 concept called optimization, which isn't too mard but more work than I want to do.
-
Wow such complicated answers.... the answer is 4. The question is If the two smaller pyramids are different sizes, however, what would be the minimum number of cannon-balls he could use to make one large tetrahedral pyramid? ... but the thing is, there are still only 20 cannonballs to use to build the pyramid and he never said you had to use all the cannonballs. It asks the MINIMUM... which is 3 on the bottom + 1 on top.
You missed this bit from the problem: "assuming he uses every cannon-ball in both pyramids". But nice try. :)
-
Maybe not the most elegant solution but might possibly be the fastest way to come up with the answer!: 1 Using Excel I created 3 columns: column 1 being a linear sequence (1,2,3 ....100); column 2 representing each layer (B1=1,B2=A1+A2); the third representing the pyramid (C1=1,C2=B1+B2) 2 I pasted these into an Access table 3 I cross joined the table to itself and added the two columns 3 4 I inner joined the query to the table on sum = column 3 Answer 120 (8 layers) + 560 (14 layers) = 680 (15 layers)
Life is like a s**t sandwich; the more bread you have, the less s**t you eat.
PhilLenoir wrote:
Using Excel I created 3 columns: column 1 being a linear sequence (1,2,3 ....100); column 2 representing each layer (B1=1,B2=A1+A2); the third representing the pyramid (C1=1,C2=B1+B2)
That's how I started out on paper, then converted that to C#.
PhilLenoir wrote:
I inner joined the query to the table on sum = column 3
I hadn't considered using a database. Points for innovation. :thumbsup:
PhilLenoir wrote:
680
That's the answer I got. :)
-
Even bruter force:
def T(n):
return n * (n + 1) * (n + 2) / 6for r in range (1, 1000):
for q in range(1, r):
for p in range(1, q):
if T(p) + T(q) == T(r):
print T(p), '+', T(q), '=', T(r)Yields:
120 + 560 = 680
1540 + 27720 = 29260
4960 + 29260 = 34220
10660 + 59640 = 70300
39711 + 182104 = 221815
102340 + 125580 = 227920
7140 + 280840 = 287980
19600 + 447580 = 467180
...Points for compact code. :thumbsup:
-
Haskell answer:
layers = scanl1 (+) [1..]
sizes = scanl1 (+) layers
combinedSizes = [(s1, s2, s1 + s2) | s1 <- sizes, s2 <- takeWhile (< s1) sizes]
newPyramids = filter combinesToPyramid combinedSizes
where combinesToPyramid (s1, s2, sum) = sum `elem` (takeWhile (sum >=) sizes)answer = head newPyramids
-------- SPOILER ------------ this gives the answer as "(560, 120, 680)", (if you load it up in GHCI and type "answer"). If you want the n first solutions, just type "take n newPyramids":
take 3 newPyramids
[(560,120,680),(27720,1540,29260),(29260,4960,34220)]I don't know Haskell, but that looks pretty elegant. Points awarded. :)