Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. IQ / Programming Quiz (Cannon-Ball Stacks)

IQ / Programming Quiz (Cannon-Ball Stacks)

Scheduled Pinned Locked Moved The Lounge
helpcomquestionlearning
85 Posts 19 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Super Lloyd

    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.

    A Offline
    A Offline
    AspDotNetDev
    wrote on last edited by
    #9

    That is the idea. Easy enough, right? So you should be able to do it, right? Right!? :)

    Thou mewling ill-breeding pignut!

    S 1 Reply Last reply
    0
    • A AspDotNetDev

      That is the idea. Easy enough, right? So you should be able to do it, right? Right!? :)

      Thou mewling ill-breeding pignut!

      S Offline
      S Offline
      Super Lloyd
      wrote on last edited by
      #10

      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.

      A 2 Replies Last reply
      0
      • S Super Lloyd

        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.

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #11

        There is a single numeric answer.

        Thou mewling ill-breeding pignut!

        R 1 Reply Last reply
        0
        • A AspDotNetDev

          Mark Wallace wrote:

          You can't make a tetrahedron with 10 cannon balls; you need 11.

          Since you don't have a picture like I do, I'll give you a hint: 1 + 3 + 6 = 10.

          Thou mewling ill-breeding pignut!

          M Offline
          M Offline
          Mark_Wallace
          wrote on last edited by
          #12

          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!

          A 1 Reply Last reply
          0
          • A AspDotNetDev

            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!

            Thou mewling ill-breeding pignut!

            T Offline
            T Offline
            tolw
            wrote on last edited by
            #13

            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 :)

            A 1 Reply Last reply
            0
            • A AspDotNetDev

              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!

              Thou mewling ill-breeding pignut!

              A Offline
              A Offline
              Andre Kraak
              wrote on last edited by
              #14

              The number of balls for each level of the pyramid increases like: 1, 3, 6, 10, 15, 21, 28. This means that the number of balls for each larger pyramid is as follows: 4, 10, 20, 35, 56, 84. So we are looking for a pyramid size that can be created with the sizes of the two pyramids that go before it. 84 is the first number for which this is possible, being combined from the pyramids with 35 and 56 balls.

              0100000101101110011001000111001011101001

              T R 2 Replies Last reply
              0
              • A Andre Kraak

                The number of balls for each level of the pyramid increases like: 1, 3, 6, 10, 15, 21, 28. This means that the number of balls for each larger pyramid is as follows: 4, 10, 20, 35, 56, 84. So we are looking for a pyramid size that can be created with the sizes of the two pyramids that go before it. 84 is the first number for which this is possible, being combined from the pyramids with 35 and 56 balls.

                0100000101101110011001000111001011101001

                T Offline
                T Offline
                tolw
                wrote on last edited by
                #15

                From the OP:

                (assuming he uses every cannon-ball in both pyramids)

                1 Reply Last reply
                0
                • T tolw

                  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 :)

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #16

                  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?

                  Thou mewling ill-breeding pignut!

                  T 1 Reply Last reply
                  0
                  • M Mark_Wallace

                    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!

                    A Offline
                    A Offline
                    AspDotNetDev
                    wrote on last edited by
                    #17

                    Virtual balls. Also, pool may help. :)

                    Thou mewling ill-breeding pignut!

                    M 1 Reply Last reply
                    0
                    • A AspDotNetDev

                      Virtual balls. Also, pool may help. :)

                      Thou mewling ill-breeding pignut!

                      M Offline
                      M Offline
                      Mark_Wallace
                      wrote on last edited by
                      #18

                      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!

                      A 1 Reply Last reply
                      0
                      • S Super Lloyd

                        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.

                        A Offline
                        A Offline
                        AspDotNetDev
                        wrote on last edited by
                        #19

                        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.

                        Thou mewling ill-breeding pignut!

                        S T 2 Replies Last reply
                        0
                        • M Mark_Wallace

                          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!

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #20

                          If they are thin mints, I fear you may never succeed, as the rate of consumption will outpace the rate of production.

                          Thou mewling ill-breeding pignut!

                          M 1 Reply Last reply
                          0
                          • S Super Lloyd

                            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.

                            A Offline
                            A Offline
                            AspDotNetDev
                            wrote on last edited by
                            #21

                            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:

                            Thou mewling ill-breeding pignut!

                            1 Reply Last reply
                            0
                            • A AspDotNetDev

                              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?

                              Thou mewling ill-breeding pignut!

                              T Offline
                              T Offline
                              tolw
                              wrote on last edited by
                              #22

                              To tell you the truth I had to Google 'tetrahedral' to begin with ( my knowledge of English is limited I'm afraid :) ), which led me to: here[^] and later (through the See Also section) to here[^] Things were kind of obvious from there :) Thank you wikipedia :)

                              A 1 Reply Last reply
                              0
                              • A AspDotNetDev

                                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.

                                Thou mewling ill-breeding pignut!

                                S Offline
                                S Offline
                                Super Lloyd
                                wrote on last edited by
                                #23

                                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.

                                1 Reply Last reply
                                0
                                • A AspDotNetDev

                                  If they are thin mints, I fear you may never succeed, as the rate of consumption will outpace the rate of production.

                                  Thou mewling ill-breeding pignut!

                                  M Offline
                                  M Offline
                                  Mark_Wallace
                                  wrote on last edited by
                                  #24

                                  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!

                                  A 1 Reply Last reply
                                  0
                                  • T tolw

                                    To tell you the truth I had to Google 'tetrahedral' to begin with ( my knowledge of English is limited I'm afraid :) ), which led me to: here[^] and later (through the See Also section) to here[^] Things were kind of obvious from there :) Thank you wikipedia :)

                                    A Offline
                                    A Offline
                                    AspDotNetDev
                                    wrote on last edited by
                                    #25

                                    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. :)

                                    Thou mewling ill-breeding pignut!

                                    1 Reply Last reply
                                    0
                                    • A AspDotNetDev

                                      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!

                                      Thou mewling ill-breeding pignut!

                                      L Offline
                                      L Offline
                                      leppie
                                      wrote on last edited by
                                      #26

                                      Pascal's Triangle[^] Also see: Pascal's Pyramid[^]

                                      IronScheme
                                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                      A 1 Reply Last reply
                                      0
                                      • M Mark_Wallace

                                        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!

                                        A Offline
                                        A Offline
                                        AspDotNetDev
                                        wrote on last edited by
                                        #27

                                        Points awarded for awarding me points (always a winning proposition). :rolleyes:

                                        Thou mewling ill-breeding pignut!

                                        1 Reply Last reply
                                        0
                                        • L leppie

                                          Pascal's Triangle[^] Also see: Pascal's Pyramid[^]

                                          IronScheme
                                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                          A Offline
                                          A Offline
                                          AspDotNetDev
                                          wrote on last edited by
                                          #28

                                          How does that relate to the cannon-ball problem? :confused:

                                          Thou mewling ill-breeding pignut!

                                          L 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups