Sunday, 9 November 2014

Week 8 - Finally Solving a Problem

Second term test..

Was fun, as always. Not much new going on, but I finally got myself to do one of the problems out of the wiki, as we were supposed to do.

Solving Problems!

I chose the line segments problem: Suppose you have a grid made up of uniformly-spaced horizontal and vertical lines. On the grid you draw a square with corners that lie on some of your grid crossings: it may be a 1x1 square, a 2x2 square, or some other size. How many line (of various sizes) segments from the grid that begin and end on grid crossings are contained in the perimeter and interior your square? What is the answer, in general, for an mxm square?
To make sure we have a common understanding of the problem, I claim there are 18 line segments in a 2x2 square.

For this problem, I decided to split the answer into a sum of line segments along the perimeter and within the area, starting with the perimeter. (L is equal to a line segment of length 1, 2L of length 2, etc..)

So any side on the perimeter of the square is going to have m*L lines, since the square itself is m squares in length. Then there will be m-1*2L lines, combining the L lines together, then m-2*3L lines, until we get to 1*mL line. Working backwards, the sum is essentially 1 + 2 + 3 + ... m-2 + m-1 + m. This can also be represented as [m(m+1)]/2, as a partial sum. Since there are 4 sides to a square, the final result for the perimeter would be 2[m(m+1)].

Now for the area, the equation is obviously going to be similar as the segments would be divided the same way along the grid, though with an extra factor due to being 2D. Since we're already counting the perimeter in the sum, we're going to leave out that line from the equation, instead of using the length of the square, m, we'll use m-1. Then the equation for the area, in one direction, would be [m(m+1)(m-1)]/2. Since there's two directions, (2D shape), we can cancel out the 2 in the denominator: m(m+1)(m-1) for the area.

Then just to add it all together, the total segments = perimeter segments + area segments:
Total = 2[m(m+1)] + m(m+1)(m-1)
          = 2m^2 + 2m + m(m^2 - 1)
          = 2m^2 + 2m + m^3 - m
          = m^3 + 2m^2 + m

As a test, plugging in 2 for m gives: 8 + 8 + 2 = 18, which is exactly as the problem states, a 2x2 square has 18 line segments. Q.E.D and all that good stuff.

Sunday, 2 November 2014

Week 7 - How Bad Can We Be?

What's the worst that could happen?

While we've still been discussing proving various proofs, we've brought in a little programming and a couple functions to give us a new set of problems.

The functions we've been looking at currently are basically just sorting functions, say you have a list of random numbers and you wish to sort them from least to greatest, find the single biggest number, or find which two adjacent numbers make the greatest sum. You will always have some case where your program/function takes the absolute longest time to complete. We've been concentrating on how to calculate how many steps a function can take, and creating formulas based on the length of the list that tell us the longest possible time/most possible steps the function can take before completing.

Damn well confusing at first, but since we're so lazy we can just overestimate (maybe extremely), it seems like a very simple concept with practice.