Monday 17 February 2014

Week 5 & Week 6: Assignment 1 and Recursion

These two weeks I worked hard on recursion and assignment 1. Though I really had a hard time on writing recursive functions, fortunately my codes work at the end.

The first 4 steps of the assignment are rather simple and we need to be careful when dealing with things related to starter code. (by the way the GUI window is impressively cool!) Step 5 is about using recursive functions to move cheeses between 4 stools within the least steps.

In last week's lab, we first practiced writing recursion, and I found it is actually difficult even though I could read and understand the recursion examples shown in class. I redid the problems and the class examples after the lab and lecture and improved. Through hard try I found a tip: don't trace too far. Do not trace a very complex example. It might frustrate you. I was usually thinking too complicated and tracing to even smaller subproblems when writing the recursive step, confusing myself, and often I lost my ideas on what to do to solve the problem. Finding the base case is not a problem to me, what I should do in this stage is simply following the instruction on how a problem is brought into smaller subproblem by calling the function itself and interpret it using codes. (P.S., If you really want to trace a function step by step, Visualizer is a helpful tool.)

To step 5 of the assignment, it's the same procedure. First moving n-i cheeses to an intermediate stool, then moving the remaining cheeses to the destination, and finally moving the n-i cheeses from the intermediate stool to the destination solves the problem. The example of Tower of Ann Hoy using three stools also gave me a good insight to implement the function.

This week we learned a new concept Tree. It's very like the SearchList we did in the lab before. It is relatively easy to understand after my practice of recursion for assignment one. The lab is not hard this week. We were asked to reimplement functions using for loop instead of list comprehension, like what we did in csc108.

Sunday 2 February 2014

Week 4: Unit test and first glimpse of recursion

This week we did some exercise of inheritance and exception in the lab. My partner and I were both not familiar with writing unittest cases, especially on how to check whether or not an exception was correctly raised. We checked the documentation and learned to use assertraises, and with the clarification later by the TA we successfully got it done. Checking the slides posted on past course websites can sometimes help as well. During the lecture, we saw several examples on recursion. We actually have seen examples of recursion since the very first lecture so it is becoming much easier to understand now. Dustin gave a very specific one with each execution clearly explained, which is helpful. He also introduced functional programming and functions with lambda to help us understand.