This is the second last week of class in this semester, and only one class left. We have been learning induction this week, which was covered in MAT137 as well as in high school, so the only difficulty is the formatting of the proof in CSC165 is slightly different than what I have learned previously. In previous courses, we usually find the base case first, so that function f(x) works, then but with some algebra we proof that f(x+1) works as well, and then we have to write a pretty long statement saying why does this work. In this course though, we assume f(x) is already working, we only have to proof f(x+1), which is simpler.
On Friday, the professor gave us a question to work in class. The question was if a rectangle that has n (rows) by m (columns) square boxes, and draw a straight line diagonally, how many square boxes will it intersect with. After trying with couple small cases, such as, m = n = 2, m = n = 3, m = n = 4, m = 2 n = 3, m = 3 n = 2, m = 4 n = 3 etc, I found that there is a pattern and I created a little method on Python that would return that number of boxes that a diagonally line would intersect with.
def diagonal(n, m):
‘’’ (int, int) -> int
Return the number of boxes that a diagonal line will intersect with, assuming m and n are larger than 1’’’
if m = n:
return m
elif m > n:
return 2n
else:
return 2m
Basically, if the rectangle is a square, then the diagonal line would intersect with the number of rows or columns boxes; else the diagonal line would intersect with twice of the number of rows or columns depending on if there are fewer rows or fewer columns.