Thursday, 1 November 2012

Bottle Cap Algorithm - Week of October 29th

To work at the algorithm I set out to find last week I made a chart comparing the length of the side of the bottom most triangle, the 'area' of the triangle, and the 'volume' of the pyramid for 5 cases (i.e. base triangle with 1 bottle caps through length 5).  I noticed that the area of a triangle for any number n of bottle caps on one side is going to be n + (n-1) + (n-2) + ... +1 = A.  This can be expressed as (n(n+1))/2.  If your willing to take my word for it that thats true then don't bother reading the next paragraph.

In case you are the sort of reader who would demand that this be proved, which you are certainly entitled to do, the simplest proof is that by induction.  We know the formula holds for n = 1, since 1 times 1 + 1 is 2, which divided by 2 is 1, the A we should expect.  Now let us assume the function is true for the natural number n, then we shall see if that implies it is true for (n-1).
A(n-1)=((n-1)((n-1)+1))/2 = ((n^2) - n)/2 = ((n^2) - n + 2n)/2 - (2n)/2 = ((n^2) + n)/2 - n = (n(n+1))/2 -n
which if true for n implies A(n-1) = A(n) - n = n + (n-1) + (n-2) + ... + 1 -n = (n-1) + (n-2) + ... + 1
Which is exactly what we are looking for. Since our function is true for n=1 and if it is true for any n it is true for n-1, then it is true for all natural numbers n.

So after finding an algorithm to find the "area" of a triangle arranged in the way described last week, it became clear than the "volume" of one of the pyramids would be a sum of the areas of all the triangles that make it up.  However, we cannot simply take the bottom area, say An, and then plug that into the same formula above because An-1 won't be the next natural number.  So we have to find another way to take the sum of An + An-1 + ... + A1 = Vn.

I'm going to try and think of a way to put this in a closed form as we did above for finding A.  If we can find an algorithm for mapping some An to Vn then we can consider the algorithm that takes n to An and then the algorithm that takes An to Vn.  This will be a composite of two functions, maybe it makes sense to consider this a composite algorithm.

Theo

No comments:

Post a Comment