Saturday, February 16, 2013

Problem Solving: Diagonals

On Friday Feb. 15, we were given the "diagonals" problem in class. It seemed easy enough at first. But, as it turns out, my initial solution was far from perfect.

The problem: Draw a diagonal in a rectangle of m rows and n columns. Find out how many of the grids the line passes through the interior of.

The plan: As with folding, make enough examples to find a pattern.

We drew rectangles from 1x1... 2x1... 2x2 up till 5x5, and from there devised a pattern:
   -for m is odd, the number of shaded squares is m + n - 1 if m != n
   -for m is even, the number of shaded squares is m + 2 [[(n-1)/2]] (where [[]] is the floor function) if m != n
   -for m = n, number of shaded squares is simply m or n.

I showed my solution to Professor Danny who informed me that there were problems with my solution involving multiples. So I made a bunch more examples and compiled that into a new chart.


n
m12345678910
112345678910
222446688
3343676910
444648810812
556785101112
66668106121214
7789101112714
888108121214816
999
101012141610


The 9 and 10 columns are incomplete because I ran out of space and didn't actually draw them. I noticed that the pattern was only broken when m was divisible by n or n was divisible by m. (but sometimes not even then).

It seems, from the exceptions I found in the chart I made (3x6 and 4x8) that the number of shaded squares is then equal to max(m,n), which also works for 2x4. So I think adding this condition, if m%n ℕ then number of squares the diagonal passes through = max(m,n) would fix the pattern. 

Looking back: I didn't really get stuck anywhere, it was a fairly straightforward process, though I stopped working on it for a while after class. I still don't know if I have the complete solution (probably not, this did not take nearly enough time) but so far I didn't really get stuck.

No comments:

Post a Comment