Our first CSC148 assignment was to code a game in which we were to move a stack of cheeses from an initial stool to a destination stool, without placing a larger cheese on top of a smaller cheese. When we were first assigned this project, I had remembered doing a similar puzzle to this (called the "Tower of Hanoi") and was able to recall a strategy in completing the game. After being able to visualize a solution to the game, regardless of the number of stools or cheeses, and through discussion with my partners for the assignment, implementing the code into Python became a somewhat easier task.
I enjoyed working on this assignment for a couple of reasons. Firstly, it helped me practice coding using recursion. In this game there is a least number of moves to move the stack of cheeses depending on the number of cheeses to move. This means that moving a large amount of cheeses uses the same strategy as moving a smaller amount of cheeses. This is a recursive problem, because once we figured out how to move a small stack of cheeses using the least amount of moves (base case), we are able to recall this solution when dealing with a larger instance. Another reason I enjoyed this assignment was because of the opportunity to work in a group. I feel that I am able to learn and grasp content easier when I work through it with others; sharing knowledge and insight.
With this assignment completed, I plan to use reading week to prep for our first term test which will cover quite a bit of content such as OOP, inheritance, recursion and much more.
(Ending these blog posts has always been troublesome for me so I'll just conclude here and wish everyone a productive reading week!)
Thursday, 20 February 2014
Monday, 3 February 2014
Intro to Recursion
In the last set of CSC148 lectures we were introduced to recursion, which at the time I knew nothing about other than "it is a technique used to solve problems". Due to my (terrible) lack of knowledge of the subject I decided to google "recursion" to learn more about the topic, and found something interesting. After I made sure I typed in recursion correctly, google still suggested this:
At first I didn't know that this was done purposely by google, but after further investigation of recursion I knew why google decided to add this little "easter egg".
I now understand that recursion involves some sort of repetition (because clicking the suggestion in google led to the same page). When implemented in programming to for example, a function, it would mean allowing a function to call itself.
The example we did in class using Python's turtle also helped me understand recursion but in a more visual sense. We commanded these drawing turtles to draw "tree bursts" starting with the base case of level 1 then gradually increasing the levels too see how recursion was being represented. As the levels increased, I saw that the level 1 tree burst was being used to draw the level 2, and 3 and so on.. tree bursts. From this, I understood that when facing a recursive problem, it's solution will come from solutions to smaller or the most basic instances of the same problem.
With that being said, my goal this week and perhaps next week will be to master recursion, which will not just help me complete our first CSC148 assignment, but will help me in many ways throughout my computer-programming journey.
Subscribe to:
Posts (Atom)