Friday, 23 November 2012

Wiki Assignment and Koch-curve - Week of November 19th

I just finished the third part of the wikipedia assignment and ran into something I had not been expecting (I suppose I should have written a check-expect).  One the the pages I was meant to edit has already been fixed.  This doesn't seem unreasonable to me, I could hardly expect the wikipedia world to know that I intended to do that later on and to wait until I had time to do it.  None the less, it does beg the question, how am I going to get graded on the assignment? I did put considerably more effort into the second page I edited to try and compensate for this so maybe the weight will be shifted onto my review of that single page.  Alternatively I could have found a new page requiring editing and done it on the fly, although that would have felt a little rushed.  Either way I did have a good look at the wikipedia process and community which was I believe the purpose of the assignment.

On another note, I recognized the koch-curve we worked with in the last lecture relates to the material in my analysis class.  If we were to take a koch-curve of infinite iterations then it would be continuous everywhere and differentiable nowhere, which is kind of cool if your into that sort of thing. The reason being is that there will be a 'bend' at every point on the curve, and we can take the derivative of a function at a 'bend'.  Not really computer science so far as I know but I thought the connection would be worth mentioning.

Theo

Saturday, 17 November 2012

DrRacket recursive definition - Week of November 12th

I never did have much time to think of a way to take the sum of the areas of the pyramid levels, not yet anyways.  I did figure out how to make drracket do it 'the long way' however.  I used the recursive definitions we learned in class to make racket take the sum of the bottom layer of a pyramid then work its way up. It was pretty straight forward and looked like this

(require picturing-programs)
(define (sum n) (/ (* n (+ n 1)) 2))
(define (vol n)
  (cond
    [(equal? n 1) 1]
    [else (+ (sum n) (vol (- n 1)))]))

It does feel a bit like cheating and I do still plan on trying to think of a single expression for the volume. It is neat to see so easily that the 'volume' of one of these pyramids with a bottom side of n=200 is 1,353,400 bottle caps. 

Theo

Wednesday, 7 November 2012

Recursion and Clock Project - Week of Nov 5th

Regarding the ongoing algorithm project, I have not had a chance to work out a formula for the sum of the areas of triangles that make up one of the pyramids; but I do hope to find some time this weekend.  I did notice today in class however that the algorithm I am searching for fits with the definition of recursion.  Given some n we can calculate the A, then if n-1 is not zero, then add the A' of the row with sides length n-1 to A, and so on until we come to n-n=0 and we stop.  I suppose if all else fails I could just use a conditional in DrRacket that takes n->V.

Having just finished the first project I feel much more confident in my DrRacket skills than ever before.  I did get stuck on the clarify-image definition for a while but thankfully Professor Heap sorted that out in class.  Before that I had tried to convert the image to a list, then map the function clarify-color to every element of the list, then convert this updated list back to and image.  I would have made it work too if it weren't for the width and height arguments needed to put the image back together properly.

I changed the hands of the clock for the project to three thin black rectangles (classy and understated in my opinion) but soon realized that half of the definitions that needed fixing were totally unnecessary if we weren't using an image in a box like the ones given.  So it was interesting to see how we could simplify the clock but I figured it would only lead to confusion if the new hands I had created weren't using the definitions that we were required to fix or write check-expects for, so I kept the original ones.

Theo

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