This week was pretty much all about the midterm. I didn't know exactly what to expect, but I thought to myself, "what are the things that the professor mentions every week?". So I figured that there would probably be a question on the midterm involving a list comprehension, and one involving recursion.
As it turned out, question 1 was computing some instances of a recursive function.
Question 2 involved writing a recursive function that uses a list comprehension.
Question 3 was implement a class with two methods that use list comprehensions.
Luckily my guess was spot on.
I hope it turns out alright, I feel pretty confident about my performance, although I'm not sure if I was supposed to write an initializer for the subclass FunctionalList. Hopefully in the absence of a subclass initializer it just calls the superclass constructor. Hopefully.
I went in to question 1 with a bit of an edge, because during the assignment I had computed a bunch of those M(n,i) least number of moves calculations by hand. I was trying to figure out which n's it was working optimally for (where n is the number of cheeses to move). Before I wrote a function to calculate the optimal split, I tried n // 2, which is optimal for some cases but not others. In the darkest hour I hard coded a bunch of control flow that used n // 2 for n = 5, 6, 9 and (n + 1) // 2 for n = 3, 11, 15 ... etc. It was hideous and confusing, but it worked up to n = 14, with no discernible pattern for the optimal i. In hindsight, if there was a discernible pattern, it wouldn't be an open problem in mathematics. But it was early in the morning, and I was pretty heavily caffeinated.
No comments:
Post a Comment