Friday, 3 April 2015

Slog #10, Last Slog

    Throughout most of the course, writing out recursive functions for binary trees, has been the major hurdle for me. The lab that illustrated this most deeply was lab 6.

    I was able to complete all he functions on lab 6, but after I did this I didn't feel like I had improved my skills in any sort of way. Most of the functions required multiple attempts for me to get them right, and by then I was merely using guess and check to tweak my functions until they worked. By the time they did work, I didn't have a very clear understanding of what actually was going on. The exam is in a few weeks so I'll have to keep on practicing these types of problems.

    I didn't have any significant dilemmas understanding the other concepts we learned in class.

     Outside of class work, stress was the another problem for me. I was told by a friend that this year, the cut-off limit for the CS specialist was being raised due to there being too many people applying to CS. I don't know what the new cut-off is, but it was enough to cause me a lot of unnecessary worry. In general, I do pretty well on my assignments and tests but I have a habit of over-thinking minor problems. This can sometimes cause me to burn out from the stress.

    Even right now as I write this, there's a sense of worry gnawing away at the back of my head. Although I haven't been able to get rid of the stress completely, I was able to find ways to placate it. For one, I found that scheduling my days and weeks works very well to lowering my levels of stress. I think that if I feel like I have greater control over my life, I will be less stressed overall.

   Overall, this semester was a very interesting semester. I'm getting kind of tired right now, so I'll end it here until I think of more stuff to write.

Slog #9, Looking back at Past Slogs

    So it's been about a few weeks, and class is almost over so I guess it's time for me to look back over a past SLOG post.

    I guess I don't have much of a choice as to which SLOG post I should choose. The only SLOG post that isn't a CS diary entry is basically my first one on why geeks should learn to write. As a result, to fill this SLOG post up, I'll look over my first SLOG and compare my opinions then to my opinions now.

    To be honest, I still largely agree with what I wrote initially, except I do admit that I made too many grand generalizations. I don't think I can be blamed too harshly, since I suffer perpetually from writer's block. Regardless, back to the topic.

    Over the last few weeks I met many people who were geeks (likes video games, CS students, generalizing again), but who were also very good at expressing themselves. I'm actually a little bit jealous of people like this since expressing myself clearly is a problem I have at times.

    Anyways, getting back to the point, I think geeks should still learn to write, but I no longer believe that geeks are generally bad at expressing themselves through speech.


   Comparing my own experience in these SLOGs to other people's experiences is very difficult since at least half the class doesn't seem to write them. There are a few well-organized and dedicated students who regularly write these entries but I have a feeling that their experiences don't represent the experiences of the rest of the class. I don't want to sound elitist, but I think most of these SLOG posts I have read are pretty generic - what you would normally expect tired, stressed students (like me) to write at midnight.

     The one true benefit I got from writing these posts, is that they gave me clarity of what I had done in CSC148 and helped me schedule what to do next. When my thoughts were on paper (or on the computer), I also felt a little bit of relief and less stressed.

Slog #8

    I can't believe I spent that much time studying for that test. On the Monday and Tuesday right before test 2, I must have spent at least 4 hours each day. The only thing I did for those two days was review labs.

    Some of these labs questions are really difficult, especially recursive functions like list_internal_between. If any of these labs appear on the test I would be screwed. Since I didn't have much time left, I copied the answers to every single lab onto my cheat sheet. God bless, without a cheat sheet I would not be passing this test.

### After Test 2

    So after the test, I came to the conclusion that test questions will be almost the same as lab questions. Only one question in the test was actually hard and that question was (if i can remember the name). to write the function list_even_between. This was exactly the same as a lab question I wrote down on my cheat sheet.

    I can't believe how lucky I was on this test. To be honest, if I didn't write this function on my cheat sheet, I would not have been able to answer that question.

    In addition, I wrote down the definitions for post-order, in-order and pre-order tree traversal on my cheat sheet. This too turned out to save me a few marks. Other than that, I had no problems during the test.

### In Class

In the last week, we spent some time working on testing and we also looked over this problem:

N = 5
M = 2
def f(N):
    return M * g(N + 1)
def g(N):
    return M * N
def h(N):
    return f(g(N))

I'm still not fully sure how this problem works. I'll do some asking to understand it.


Monday, 30 March 2015

Slog #7

    So this week, I found out that I had done my minimax function completely wrong the day before it was due. My understanding of minimax was wrong the entire time.

    I thought Minimax was a type of strategy where the computer would calculate every possible game state that can result from a move and then return the chance of winning for that move.

    So for example, let's say that the computer can make 3 possible moves. Minimax would go through each of these moves and find every possible final game state. It would then find the "average" of all these final states and rate each of these three moves based on the percentage of win states to total states.

So minimax might end up generating something like this:

                Move 1: (40% win chance)
                Move 2: (70% win chance)
                Move 3: (80% win chance)

Based upon my minimax, the computer would choose move 3.

    The fundamental error here is that I assume that my computer is going up against an imperfect opponent. A real minimax is supposed to assume that the computer is facing a flawless opponent.

    Knowing that I had such a huge problem in my program, I had to pull an all nighter to finish minimax.

    By a miracle, it turns out that all the information I ever needed on minimax was on wikipedia. There was nothing to stress over the entire time.
http://en.wikipedia.org/wiki/Minimax

   There was more than enough information for Minimax, Not only that, there was even pseudocode for minimax. With this much useful info, I finished minimax in 2 hours.

In addition to finishing minimax I also reviewed a few of the past labs for recursion. I found some of the recursion problems, (especially for binary lists) to be very hard. Not so difficult that I couldn't solve them with enough time but difficult enough that they can stump me for a while. I am going to have to practice these problems alot if I want to succeed on the test.



Slog #6

I spent most of the week working on assignment 2 and I was met with quite a few significant problems. The first problem I had was with the minimax function.

For some apparent reason, whenever I attempted to run minimax with Tippy, the minimax class would always crash midway. I did what I normally do in the event of an error, I filled my minimax class with print functions so that I can track different values in the minimax class.

So I went and tracked what happens in minimax when I run Tippy with a 3x3 board. What I found was incredibly confusing. For some reason, every time I ran the AI, minimax would load through only 9 different game states and then crash.

And for some reason, the last game state would always look like this:

[X,O,X]
[O,X,O]
[X,O,X]

I spent the next hour trying to find the problem and I still had no clue what was going on so I decided to sleep on it.

After some thinking I finally realized what was going on. In every one of my Tippy game states, I had a two-dimensional grid ([][]) that corresponds to my grid.  Every time I made a move I would add an X or an O on an empty spot in the grid and then I would return the new corresponding game state. The problem here was that 2D arrays were mutable and as a result, my initial game state (which is supposed to remain an empty board) was consistently being changed every time minimax was called.

This perfectly explained why my minimax would crash after printing 9 states. This is because after going through 9 states, my initial state was already full and minimax could not find any more moves to make.

This problem was very interesting for me because I made use of knowledge about mutability I had learned in CSC108. Solving this problem also made me feel like I had done something substantial.

Sunday, 1 March 2015

Slog #5

Please grade my summary of objected oriented programming this week.

I'll update this post once I'm done documenting Assignment 2.

Saturday, 21 February 2015

Object Oriented Programming, Slog #4

Object Oriented Programming, starts off with the concept of classes and objects. An object is something that can perform a set of actions/methods. A class is a blueprint of an object. For example, we can have a blueprint of a plane like the following:

Blueprint of a plane:
-          Wings
-          Cockpit
-          Fuel Tank
-          Instructions on how to combine parts to build plane
-          Etc
Now let us imagine that we have an actual plane. So now we have a blueprint of a plane and an actual plane. The blueprint of a plane is a class, while the actual plane is an object. We say that the real plane is an instance of the plane blueprint. Technically, objects and instances are the exact same thing, but we usually use the word instance to describe an object that is of a class.

Let’s say that we have two classes. One class is the plane blueprint class from above. Another class is blueprint for a fighter jet we have here:

Fighter Jet:
-          Missiles
-          Guns
-          Wings
-          Cockpit
-          Fuel Tank
-          Instructions on how to build fighter jet
-          Etc

Fighter jets are a subset of planes. Fighter jets are planes.  Also notice how Wings, Cockpit and Fuel Tank are all shared by Fighter Jets and planes. We can say that fighter jet is a class that inherits from class plane. So next time we can write a blueprint of a fighter jet like this:

Fighter Jet(Plane):
-    Guns Missiles
-    Instructions on how to build a fighter jet
-    Etc

One last thing to mention is that classes also have methods. On the fighter jet class, we have instructions on how to build a fighter jet. This is an initializer method (__init__) that is called whenever we want to create a fighter jet object. In addition to this method, we can also add methods such as 'Fire Missiles' or 'Fly', that allows this fighter jet object to interact with itself and with other objects.

So after doing some tweaking we have a final Fighter Jet class:

Fighet Jet(Plane)
- Guns Missiles
- Instructions on how to build a fighter jet
- Fire Missiles (This is a method)
- Fly (This is a method)

Why did people invent object oriented programming?

    I’m not an incredibly experienced programmer, so I can’t really give an expert opinion. However, my guess is that objected oriented languages are much more efficient for the programmer. After all, with OOP, the programmer doesn’t have to repetitively write out the same code over and over again (e.g he doesn’t have to keep on rewriting a plane blueprint) when he can just initialize a single object and all the code is automatically done for him.

http://antiaromatic.blogspot.ca/2015/02/lab-5-work.html?showComment=1425265486615#c6709566295146482820

A slog that I commented on. Very helpful info on Lab 5.


Tracing Recursions, Slog #3

    In high school, my teacher made the class write a few easy recursive functions, for example calculating a specific value in the Fibonacci sequence. Some of these programming exercises I completed in high school gave me a half-decent foundation in recursions.

    The recursive functions we learned in class all took in a list as a parameter. In addition they all made use of the isinstance() function and a single if statement so they were pretty simple. The problem I found, was visualizing the function calls. Since we are repetitively visualizing function calls within function calls, it can get quite frustrating to keep track of each call.

     I found that tracing recursive functions becomes much easier if you know how the function works. So what I try to do when I approach a tracing problem, is first to figure out what the function does, and then do the tracing exercises. If you know what the function does, tracing it doesn’t become very difficult. 

    Obviously, the method above only works for very easy recursive functions. Some recursive functions, like quicksort  are much harder to figure out intuitively. Just look at the code we were give in class. 


def quick_sort(L):
    ''' (list) -> list

    Return a list containing the same elements as L in ascending order.

    >>> quick_sort([])
    []
    >>> quick_sort([5])
    [5]
    >>> import random
    >>> L = [1, 2, 3, 4, 5, 6, 7]
    >>> random.shuffle(L)
    >>> quick_sort(L)
    [1, 2, 3, 4, 5, 6, 7]
    '''
    if len(L) < 2: # there's nothing to sort
        return L
    else:
        return (quick_sort([x for x in L if x < L[0]]) + 
                [L[0]] + 
                quick_sort([x for x in L[1:] if x >= L[0]]))



Had there been no description of what this function does, I would be hard pressed to trace a function call. The way to get better at tracing recursions I guess, is probably the same as getting better at proofs in math. Just do more problems.

Reaction to first few weeks and assignment 1, SLOG # 2

Overall, I found that the first few weeks of 148 was not that much more difficult compared to 108.  Still, there is a difference between the courses. For example, assignments and learning styles in both courses were very different. The 148 material seems to be more conceptual and thinking-based compared to 108’s focus on programming knowledge. Also, 148 assignments give students much more freedom compared to 108 assignments. Just take assignment 1 as an example. Assignment 1 was something completely different from any of the assignments in CSC108. In 108, assignments were very rigid and we students were not given much freedom to change anything.  Contrast that with assignment 1, where program design was all on the student.

When I first began assignment 1, I felt a little bit confused since I was used to being given direct instructions. To be honest it was a bit annoying at first, not knowing where to begin and all, but by the end it turned out to be fine. The hints on the sheet helped lot, and once I had a basic design in my head, I became pretty comfortable with the problem.


So after spending 8 hours to finish something I thought would be done in 3. I can say that I feel like programming assignment 1 feels like a consistent process of illusion and disillusionment. When I first wrote out a design for all the classes in assignment 1 I felt that everything would be easy and done within 2 hours. Then I start programming and I see all these holes in my ideas. I go back to the drawing board, redesign a few things and fix my problems. I go back to program and find more problems. Then I go back to my design and it goes on and on and on until eventually I finish. The funny thing is by the time everything actually works, I have no clue what I have done. Well, as long as everything works, I’m happy. 

Wednesday, 21 January 2015

Why should geeks learn to write? Slog #1

There are a multitude of different reasons why geeks should learn to write but the greatest one is that geeks typically are introverts. This is a fact, and there is nothing wrong with it. Many of us are familiar with what an introvert is, but to those who don't know, an introvert is someone who is quiet and typically shy. Introverts aren't necessarily insecure or poor speakers, in fact many of them make excellent speakers, but in general they don't prefer it.

Introverts are the kind of people who think before they speak and only say something when they are absolutely sure that what they're about to say makes sense. They can spend hours concentrating on a single idea, ignoring any distractions.

This makes introverts, and geeks as an extension, very good writers. Writing gives geeks the opportunity to express many of your ideas that they were too shy to say in front of a crowd. Writing gives you the time to think about what you are going to say, to ensure that everything you write will be exactly as you want it.

Another reason why learning to write can become very useful for geeks, is that writing is both a creative and logical process. It takes logical thinking to arrange your ideas into sentences and paragraphs that make sense and it takes creativity to think of new things to write about.
Both these processes are very useful in coding. In fact, I would argue that feeling you get when you're unable to think of a solution to a computer science problem is another form of writer's block.

Writing can be seen like a form of exercise for the brain. Over a long period of time it will clarify your thought processes, improve concentration and facilitate creativity - abilities that are very helpful in coding.

I think I'm finally running out of things to say, so I'll end this first post for now. Back to working on Assignment 1.