edX 6.00x – Midterm 1

With the deadline for the submission of the first midterm exam safely past, I’m now able to reflect on my performance here. 95/100 is respectable enough – although having dropped 4 out of 8 marks on the very first question, it wasn’t looking too promising early on Saturday morning. Note to self: read the question, read the question again and read the question again before submitting the answer for checking!

Fortunately I only lost one further mark (out of the 20 available for the sorting and complexity question) and managed all of the questions which required Python programs to be submitted (5 of the 8 questions on the paper) without any real difficulty at all – even though the final part of question 8 was a bit of a teaser. In real life, I think the way to have fixed the bug would have been to have thrown the code away and started again – with a solution that looked more like the second part of the question – rather than tweaking the rather strange code that was provided. But I guess the point of the exercise was to demonstrate an understanding of variable scope and how to pass functions as arguments to functions, rather than good coding style.

There was one question for which I’m particularly pleased with my answer, partly because ¬†even though I’d not come across the puzzle before I managed to figure out an elegant and recursive answer in around 3 minutes!

The problem asked for a boolean function to determine if an arbitrary number of food items (I refuse to advertise the brand) could be packed exactly into boxes holding 6,9 and 20. For example, 21 should return True (9+6+6), whereas 7 will return False.

Recognizing that the problem is easy to solve recursively (i.e. for quantities of 20) led me to this solution outline very quickly:

If the quantity requested is less than 6, return False

else if the quantity requested is divisible by 3 with no remainder or the quantity requested is divisible by 20 with no remainder, return True

else return the value of this function for the quantity requested – 20

After I’d got to this answer I did try to think about how I might create an iterative version, but nothing I tried seemed to be particularly elegant. Searching the web after the exam had closed revealed a number of different iterative solutions to this and similar problems, but in this case, a recursive answer definitely seems to be both easier to understand and to program.

The week 6 material should be out later on today and we’re just about to get into the part of the course that wouldn’t have been taught when I was taking High Level Programming ‘A’ using Pascal at Warwick University in 1982 – object orientation.

Posts Tagged with…

Your thoughts?