IQ / Programming Quiz (Cannon-Ball Stacks)
-
My shot at the answer - quick and not optimized, I'm sure :)
class Program { const int RANGE = 1000; static void Main( string\[\] args ) { int sum, p1, p2; for( int a = 0; a < RANGE; a++ ) { p1 = ( a \* ( a + 1 ) \* ( a + 2 ) ) / 6; for( int b = a + 1; b < RANGE; b++ ) { p2 = ( b \* ( b + 1 ) \* ( b + 2 ) ) / 6; for( int i = b + 1; i < RANGE; i++ ) { sum = ( i \* ( i + 1 ) \* ( i + 2 ) ) / 6; if( sum == p1 + p2 ) { Console.WriteLine( sum.ToString() + "=" + p1.ToString() + "+" + p2.ToString() + "\\n" ); } } } } Console.ReadKey(); } }
SPOILER ALERT!! The answer I got is: 680 = 120 + 560 EDIT: I am aware I could have just stopped looking after the first hit - but I was also curious if there would be a lot of results :)
Points awarded for: correctness, elegance, quickness, and mathematical insight. It seems you found an equation for the number of elements in a pyramid for the Nth pyramid. Nice! Since you already have a better program than mine, I might as well share mine now instead of waiting until tomorrow:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (var i = 1; i <= 30; i++)
{
txtOut.AppendText(Environment.NewLine + CalculateNumBalls(i).ToString());
}
}public int CalculateNumBalls(int index) { if (index <= 1) { return index; } else { return CalculateNumBalls(index - 1) + CalculateLayer(index); } } public int CalculateLayer(int index) { int total = 0; for (var i = 1; i <= index; i++) { total += i; } return total; }
}
That just displays the number of balls in the Nth pyramid for the first thirty pyramids. I just used a calculator to see what the difference was between each number. I saved time because I didn't have to calculate all the way down (given largePyramid - mediumPyramid = smallPyramid, I could just stop when smallPyramid was larger than mediumPyramid). Out of curiosity, did you know that formula already, or did you figure it out?
-
I just made one with mints, and I had to put one in the middle on the third layer. Mind you, the mints are all different sizes and shapes -- but if they were all the same, it would have drained the fun out of it.
I wanna be a eunuchs developer! Pass me a bread knife!
Virtual balls. Also, pool may help. :)
-
Virtual balls. Also, pool may help. :)
Oh, I know the Maths, but I don't come to the Lounge for work. It's much more fun ignoring thousands of years' learning on triangular numbers, etc, and building pyramids out of mints. I've already done my serious posting of the day. It's a bit much to expect another one.
I wanna be a eunuchs developer! Pass me a bread knife!
-
Well, didn't I? I think than maybe I didn't understand the question, let me read it again...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.
You keep deleting your messages before I can reply to them, so here is what I was going to say in response to one of them... :)
There is no pyramid composed of exactly 91 balls. It goes 84, then 120. You are on the right track though. Let me phrase it another way. There are 3 pyramids: A, B, and C. A is the smallest, B is larger, and C is the largest. The number of balls in C is equal to the sum of the balls in A and B. A does not equal B. This is the question: Find the smallest possible value of C.
-
Oh, I know the Maths, but I don't come to the Lounge for work. It's much more fun ignoring thousands of years' learning on triangular numbers, etc, and building pyramids out of mints. I've already done my serious posting of the day. It's a bit much to expect another one.
I wanna be a eunuchs developer! Pass me a bread knife!
If they are thin mints, I fear you may never succeed, as the rate of consumption will outpace the rate of production.
-
10 ball give a tetrahedron of 3 levels (1 on top, 3 below, 6 below) 20 ball give a tetrahedron if 4 levels (1 on top, 3 below, 6 below, 10 below) just look at tetrahedron of increasing sizes and forecast what was going to happen... [EDIT] each level number of balls = N + previous level (i.e. level N has N(N+1)/2 balls) then you can easily write the table (1, 3, 6, 10, 15, 21, etc...) and play with the numbers...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.
Super Lloyd wrote:
level N has N(N+1)/2 balls
Points for realizing this. I too realized this, but couldn't remember the exact function. :thumbsup:
-
Points awarded for: correctness, elegance, quickness, and mathematical insight. It seems you found an equation for the number of elements in a pyramid for the Nth pyramid. Nice! Since you already have a better program than mine, I might as well share mine now instead of waiting until tomorrow:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (var i = 1; i <= 30; i++)
{
txtOut.AppendText(Environment.NewLine + CalculateNumBalls(i).ToString());
}
}public int CalculateNumBalls(int index) { if (index <= 1) { return index; } else { return CalculateNumBalls(index - 1) + CalculateLayer(index); } } public int CalculateLayer(int index) { int total = 0; for (var i = 1; i <= index; i++) { total += i; } return total; }
}
That just displays the number of balls in the Nth pyramid for the first thirty pyramids. I just used a calculator to see what the difference was between each number. I saved time because I didn't have to calculate all the way down (given largePyramid - mediumPyramid = smallPyramid, I could just stop when smallPyramid was larger than mediumPyramid). Out of curiosity, did you know that formula already, or did you figure it out?
-
You keep deleting your messages before I can reply to them, so here is what I was going to say in response to one of them... :)
There is no pyramid composed of exactly 91 balls. It goes 84, then 120. You are on the right track though. Let me phrase it another way. There are 3 pyramids: A, B, and C. A is the smallest, B is larger, and C is the largest. The number of balls in C is equal to the sum of the balls in A and B. A does not equal B. This is the question: Find the smallest possible value of C.
I deleted them because I finally understood the question and saw that someone answered it! :P
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.
-
If they are thin mints, I fear you may never succeed, as the rate of consumption will outpace the rate of production.
I'm going out in a bit to get some dolly mixture, and some jelly babies to build the pyramids. I'll nip up and give your OP a five, because it's really inspired me to be productive, today.
I wanna be a eunuchs developer! Pass me a bread knife!
-
Points awarded for sharing your research techniques, for pointing me to this GIF, and for figuring out a solution so fast without even knowing what a "tetrahedral" is. :)
-
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!
-
I'm going out in a bit to get some dolly mixture, and some jelly babies to build the pyramids. I'll nip up and give your OP a five, because it's really inspired me to be productive, today.
I wanna be a eunuchs developer! Pass me a bread knife!
Points awarded for awarding me points (always a winning proposition). :rolleyes:
-
How does that relate to the cannon-ball problem? :confused:
-
How does that relate to the cannon-ball problem? :confused:
AspDotNetDev wrote:
How does that relate to the cannon-ball problem?
Exercise for the reader ;p (Can you not see the symmetry?)
-
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!
The way I see it, each stack must have a number of cannonballs from the set {1, 4, 10, 20, 35...} Now we are looking for a minimum A and B, both out of this set, so that the sum of both is also in the set. From your example we know it works for two stacks of 10 cannonballs, so the sum cannot be greater than 20. Therefore A and B must both be in {1, 4, 10} Now you can simply try all combinations:
A | B | Sum | Sum <= 20 | Sum in set
1 | 1 | 2 | Y | N
1 | 4 | 5 | Y | N
1 |10 | 11 | Y | N
4 | 1 | 5 | Y | N
4 | 4 | 8 | Y | N
4 |10 | 14 | Y | N
10| 1 | 11 | Y | N
10| 4 | 14 | Y | N
10|10 | 20 | Y | YSo here we have it. Your example with two stacks of 10 cannonballs already is the minimum. Edit: Added pre tags to make the table readable
I'm invincible, I can't be vinced
-
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!
Hi AspDotNetDev, In this comment to your good self(ves?)[^], I think you raised an issue appropriate for "Site Suggs and Buggs:" and I have expressed my views there:[^]. And, to this starving worm on a wilted cabbage leaf, the issue raised by that post is an even more compelling puzzle than the stacking of cannon-balls, although I am not denigrating the value of considering the stacking of cannon balls ! best, Bill
"Science is facts; just as houses are made of stones: so, is science made of facts. But, a pile of stones is not a house, and a collection of facts is not, necessarily, science." Henri Poincare
-
The way I see it, each stack must have a number of cannonballs from the set {1, 4, 10, 20, 35...} Now we are looking for a minimum A and B, both out of this set, so that the sum of both is also in the set. From your example we know it works for two stacks of 10 cannonballs, so the sum cannot be greater than 20. Therefore A and B must both be in {1, 4, 10} Now you can simply try all combinations:
A | B | Sum | Sum <= 20 | Sum in set
1 | 1 | 2 | Y | N
1 | 4 | 5 | Y | N
1 |10 | 11 | Y | N
4 | 1 | 5 | Y | N
4 | 4 | 8 | Y | N
4 |10 | 14 | Y | N
10| 1 | 11 | Y | N
10| 4 | 14 | Y | N
10|10 | 20 | Y | YSo here we have it. Your example with two stacks of 10 cannonballs already is the minimum. Edit: Added pre tags to make the table readable
I'm invincible, I can't be vinced
Nope, there was a stipulation that A and B are different. Otherwise, you are one the right track.
-
AspDotNetDev wrote:
How does that relate to the cannon-ball problem?
Exercise for the reader ;p (Can you not see the symmetry?)
leppie wrote:
Can you not see the symmetry?
They both involve triangles. Other than that, nope.
-
You keep deleting your messages before I can reply to them, so here is what I was going to say in response to one of them... :)
There is no pyramid composed of exactly 91 balls. It goes 84, then 120. You are on the right track though. Let me phrase it another way. There are 3 pyramids: A, B, and C. A is the smallest, B is larger, and C is the largest. The number of balls in C is equal to the sum of the balls in A and B. A does not equal B. This is the question: Find the smallest possible value of C.
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;
-
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!
I did this using an old technique: pencil and paper. It is more complicated to explain than it was to do. Basically, I wrote 3 columns of numbers: Col 1: 1, 2, 3, 4, etc [represents the no of levels in the pyramid) Col 2: 1, (corresponding no in col 1 + prev number in col 2), ... [represents the no of new balls in the new level of the pyramid] Col 3: 1, (corresponding no in col 2 + prev number in col 3), ... [represents the total no of balls in the pyramid] and then looked for a number in col 2 that was the same as a number in col 3 which is a pyramid's worth of balls that is also a level's worth of balls [Actually, I didn't bother with col 1 - I could work that one out without writing it down, but it is easier to explain with it there] My solution is ... The first one found was 120, so the solution is 120 + 560 (no in col 3 before the 120 in col 2) = 680 (no in col 3 next to 120 in col 2). (select the text in the gap above, e.g. by dragging the mouse, to read it) Of course, this discounts the possibility that a pyramid might split across multiple levels in a combined pyramid. Just in case I had made a simple arithmetic error, I checked in MS-Excel: Cell A1 = 1, B1 = 1, C1 = 1 Cell A2 = =A1+1, B2 = =A2+B1, C2 = =B2+C1 Cells A3 through C17 = Copy and paste A2 through C2 [I've had to edit this entry twice - suffering from lysdexia (!) today].