This
week we continued to learn about recursion. What helped me to
understand recursion more easily was learning its structure, which
consists of the general case and the base case(s). Writing recursive
code for the base case first and then applying the concept to the
general case makes the process, which can sometimes get messy, a lot
clearer to me. We were also shown many different applications of
recursion, such as in nested lists, writing a function that can
return permutations, and drawing graphics. The turtle animation was
very interesting and really showed me, visually, how powerful
recursion can be.
We
then looked at an example of namespaces to see the differences
between defining variables globally, nonlocally, and locally. We were
told that we should not reuse variable names even if they are not in
the same scope.
I've
also started to think about assignment 1. The code for the
move_cheeses function that we were presented with in lecture has
proven very helpful to my understanding of the recursive nature of
this game. I plan to use the example code as the “base case” of
the tour_of_four_stools function (which is one of the later parts of
the assignment, so I'm not completely certain how it's going to work
just yet, but I think it will help a lot).
No comments:
Post a Comment