Sunday, February 23, 2014

Week 6 - Assignment 1 & Trees

Assignment 1 is done! 

The week before reading week was a busy one: finishing A1, doing two other midterms, and in the meantime trying to process the new information we were learning about trees in class. Out of all of these tasks, I found Assignment 1 the most enjoyable. I had already completed the bulk of the assignment and in the few days before it was due, I mostly just needed to write the code for the tour of four stools, and (my favourite...not): docstrings!

The hard part about writing the tour of four stools function for me was keeping track of all the different stools throughout the recursion. I traced out the code on several pieces of paper before I finally figured out how to write it. The hardest part was figuring out which intermediate to use as which parameter in the function - although in the end it didn't really make a difference. My function worked for up to 20 cheeses (and is probably still calculating the result for 100) so I hope I'll do well on this assignment. Speaking of which, I have been anxiously checking MarkUs every day for the past week, but expectedly, no marks up yet. 

The part of A1 I found the most difficult was the function where you asked the user for input, to play the game manually from the console. This is another example of the big leap from 108 to 148: in 108, we were supposed to assume all user input would be of the correct format. It took a while and several if statements, but eventually I got a functioning way to play the game. 

In class we learned about trees. I found trees to be the most difficult use of recursion to understand that we've seen so far, because we were creating a class that was defined recursively. I'm interested to see what we will use trees for, as I've heard that they are used a lot in more advanced programming. 

Now that that's all done, time to study for the midterm!
Good luck everyone!

Monday, February 10, 2014

Week 5 - Namespaces & Assignment 1

Hello again everyone,

Assignment 1 is due in a few days and Piazza has been overflowing with questions! I had originally intended to keep up with all the activity on Piazza from the start of the course, but seeing as there are 165 posts for A1, I don't think I'll be able to anymore. 

This week in class was a mash-up of Python namespaces and tips for A1. The Python namespace stuff was interesting: it seemed very confusing at first but once I understood it, I realized it was easy to follow if you trace the code carefully. One thing I find interesting about this and other topics in 148 is how much there is to know about Python that we didn't learn in 108. It seems like every week, there is some new topic of which I wasn't even aware based on what I learned in 108, and it is amazing to see how much I overlooked last semester. 

I finally started Assignment 1 last week, and was excited to get started because I was really eager to solve the game. I've always liked math puzzles and this one was definitely a tough one. There were two parts to this assignment: 1) writing the code, and 2) solving the problem. Each one presented its own difficulty: it took me a while to really understand the given code enough to know exactly how to implement the methods. Once I started though and realized I was going to use a dictionary for the TOAHModel, everything pretty much fell into place. The second part took me longer: I spent a long time trying to find a pattern or a formula for the "i" value that would give the least number of moves, until eventually I realized you could just obtain it with the code. I think the most important thing that I learned was not to divide this assignment into Computer Science and Math, but to use them hand in hand. To complete this assignment, I'm going to try putting that into practice.

Good luck with Assignment 1 everyone!



Sunday, February 2, 2014

Week 4 - Recursion Depth

Hi everyone,

This week we went into more depth on the topic of recursion - namely looking at recursion depth! I found the tree burst function very cool as it shows that recursion can be nice to look at as well as a cool concept. When I first heard about recursion, everyone seemed afraid to speak of it, but so far it hasn't been that bad. I was confused at first but now it makes a lot of sense programming-wise. I've also started seeing examples of it in my every day life.  

We learned about recursion depth this week and it was interesting because it made me think of something my Calculus professor mentioned a few weeks ago. He said someone once asked the question "How long is the coast line of Nova Scotia?" People could give a rough approximation, but of course it's not perfectly straight all along the coast line. So for those places where it wasn't straight, you could zoom in and then it would be made up of a series of straight parts right? Well on each bumpy part, you zoomed in and there were more bumpy parts. And then you could zoom in on that and there would be more bumpy parts each time you zoomed in and this would happen infinitely. As a result, no one knows the length of the coastline of Nova Scotia! This is an example of infinite recursion depth:
def coastline_length(coastline):


return (sum ([length of segment for segment of coastline]) if segment is a line, else coastline_length(segment))

It is cool to see examples of recursion depth in every day life. Here is a picture of recursion in nature, seen in fractals (in this case a cauliflower!)
Have a good week!