WAIT WHAT?!? We're done? Well that definitely flew by. I'd like to say that I very much enjoyed this course and the assignments were very fun. I especially enjoyed the game making assignment as it was very fun seeing your program actually do something interactive. Whereas in CSC108, we just had to implement methods and didn't really see how they all worked together. It was a very rewarding feeling after spending nights and nights trying to get the program working but once it did, it was such a priceless feeling.
I was quite sad when labs were cancelled due to strike because that was one thing I was actually excited about. Going to labs to test if we understood what we learned in lectures. It was actually cool to have hands on experience in a lab ad collaborating with others in the section to prove some problems. Without labs, it was a struggle to understand a few concepts without TAs and working on them by yourself is not enjoyable either. I'm just glad that I got through them and the tests were very straight forward and as long as you've worked and tried the labs, you were good for them.
I think the course itself has some interesting concepts that we learned this term such as recursion. As confusing as it is, it's quite cool to call its own function in its own method. Working with trees was also interesting. Most of the things that we learned really improves efficiency as seen in StrategyMinimax.
I would say that it was a great term and thank you to all the TAs and Proffs that made this course a great one. Also a big shout out to the Profs, even though some labs and TA support were wiped out for us, you still tried to make the impact of the strike as little as possible. We still covered majority of the content and we had a small impact on our course marking scheme. I really enjoy computer science for someone who had no prior knowledge coming in and I enjoy all of the logical thinking, problem solving and the trial and errors that it entails and I plan on continuing as a major with another major in who knows what...... :) Anyways, happy programming and it was a good semester! Cheers Geeks! :) Keep SLOG-ing. It's important (refer to week 1 post) :P
Why Do Pigs Quack
Thursday 2 April 2015
Friday 27 March 2015
Week 11
Reading my previous posts, I have seen that I had great trouble with Recursion. Now that I have done many exercises dealing with recursion, I feel pretty comfortable with them as we have done so many functions in Assignments 2 and 3 that it's coming naturally when you're trying to implement a recursion method.
Also, Linked Lists now aren't so bad. I think the trick is to continue doing exercises until you get the hang of it and start gaining comfortability dealing with these sets of problems. Anyway that's all I could really write about this week and everything else has been going pretty well.
Other news, the STRIKE IS FINALLY OVER. I don't know how the strike ending the week before school's done is going to affect our marking scheme but I feel like all of my courses have been on a rocking boat and swaying in so many directions that I don't even know what will happen. Im just hoping for the best because I really want to get the most out of my tuition fee and I feel like I did not get that this year. But hey! Welcome back TAs, I have missed you! I have now come to realize how much Computer Science courses rely on labs and tutorials to understanding and apply the concepts we've learned. I hope this doesn't happen again in the near future. It's really a struggle.
Thursday 19 March 2015
Test Numero Dos
Week 9 has been a hectic week due to having a test in both CSC165 and CSC148 and the lack of TA support. Regarding the strike, I wish it was over since most of my knowledge of concepts and problem solving are cleared up during Tutorials and Lab Exercises. So, going to the two tests were filled with uncertainty with a lack of confidence of knowing these concepts. A lot more work had to be put into studying as self teaching was the key to get by this week and tests which greatly put me behind in other courses but hey! You have to do what you have to do and balance all of your courses.
Anyway, the test was not too bad. It was pretty straight forward and it's everything that we've seen before in class for sure. I noticed that I had made a mistake in the first question when they ask what is the biggest height a binary search tree could have with 20 nodes. To my understanding, I thought that each node had an arity of 2 which made me think that it had to either have no children or 2 children so I did not think of the possibility of the tree to be just one long path of 20 nodes. But now I am aware of my mistake and this possibility.
The recursion part was alright, It was to only list the even nodes in the tree from a certain interval if I remember correctly. So if the node was in the interval, you'd have to check the left tree and right tree and so on and create an if statement that only returns that node if " n % 2 == 0".
The linked list part of this test was some what challenging. But the handy dandy cheat sheet really came clutch (Urban Dictionary: the crucial moment that comes between winning and losing)! But obviously I was winning (maybe not, we'll see) because the code was pretty similar to the lab07 exercise when "delete_after" had to be implemented, if I'm not mistaken. You just had to manipulate the code a bit to get it to check the right conditions and to add the value of the next node to the current one then skip it. Just some minor changes to that code and bam you got it. If it isn't right...... well then.... part marks, am I right? Hahaha.
Overall, not such a bad test, we'll see about that though. Anyway, the last few weeks and the final push with no TA support to get through this semester and I am...... feeling...... indifferent about it. Like I want to finish the semester already and we're so close to the finish line but with no TA support, I don't know if i'll make it there, especially with no TA help with A3 and as the exam approaches to clear any misunderstandings and concept confusion with labs. But we got this! Work hard, Program Hard! :)
Anyway, the test was not too bad. It was pretty straight forward and it's everything that we've seen before in class for sure. I noticed that I had made a mistake in the first question when they ask what is the biggest height a binary search tree could have with 20 nodes. To my understanding, I thought that each node had an arity of 2 which made me think that it had to either have no children or 2 children so I did not think of the possibility of the tree to be just one long path of 20 nodes. But now I am aware of my mistake and this possibility.
The recursion part was alright, It was to only list the even nodes in the tree from a certain interval if I remember correctly. So if the node was in the interval, you'd have to check the left tree and right tree and so on and create an if statement that only returns that node if " n % 2 == 0".
The linked list part of this test was some what challenging. But the handy dandy cheat sheet really came clutch (Urban Dictionary: the crucial moment that comes between winning and losing)! But obviously I was winning (maybe not, we'll see) because the code was pretty similar to the lab07 exercise when "delete_after" had to be implemented, if I'm not mistaken. You just had to manipulate the code a bit to get it to check the right conditions and to add the value of the next node to the current one then skip it. Just some minor changes to that code and bam you got it. If it isn't right...... well then.... part marks, am I right? Hahaha.
Overall, not such a bad test, we'll see about that though. Anyway, the last few weeks and the final push with no TA support to get through this semester and I am...... feeling...... indifferent about it. Like I want to finish the semester already and we're so close to the finish line but with no TA support, I don't know if i'll make it there, especially with no TA help with A3 and as the exam approaches to clear any misunderstandings and concept confusion with labs. But we got this! Work hard, Program Hard! :)
Saturday 14 March 2015
Linked Lists
Hello there once again Sloggers! Can't believe we're already more than half way done this Winter semester, let alone 1st year! Almost there guys, the final push!
So Week 9 talks about Linked Lists! To be honest, this concept was some what confusing to me at first and watching this video really helped me grasp the concept.
So basically the most typical structure of Linked Lists code goes somewhat like:
So Week 9 talks about Linked Lists! To be honest, this concept was some what confusing to me at first and watching this video really helped me grasp the concept.
So basically the most typical structure of Linked Lists code goes somewhat like:
cur_node = self.front #This is to set a variable to the first node in the list while <some condition here>: #Depends on the problem
cur_node = cur_node.nxt #Update the node to the next one
I think of it as a normal list but instead of looping through a list automatically, you have to keep updating the node that you want to check and if it satisfies the condition given. Also, you have to take into consideration when the list is empty, or when the you reach the end of the list or if the next node is None, or if it's size is 0, and make "if statements" that satisfy those conditons based on your method accordingly.
We had a lab to do for this concept but unfortunately, without TAs was proven to be very difficult because we didn't have the extra guide to lead us to the right direction especially that it is a new concept. But overall, the lab was not too bad but I still need to practice cases where if the loop reaches the end or if there aren't anything in the list because I tend to miss some important things in my code that will make it run incorrectly. More practice needs to be done with these methods but other than that, not too bad to get my mind around.
Sunday 8 March 2015
Week 8 - Trees and Binary Trees
This week we've been taught how to create trees and binary trees. Trees look something like this:
Trees are a set of nodes with directed edges between pairs of nodes. An edge connects a parent node to a child node. The node at the very top is called the Root Node which is the one node that does not have a parent in the tree. The parent node is a node that contains children. Also the length of the path is the number of edges in the path of the tree.
These are some more useful terminology that is helpful for the structure of trees:
- A leaf is a node with no children (such as #1, 4, 7, 10 in the diagram)
- Internal node is a node with one or more children (#5, 3, 8 in the diagram)
- Subtree is a tree formed by any node and its descendants and the edges connecting them
- Height of the tree is the maximum path length + 1
- Depth is the height of the whole tree minus the height of the tree rooted at that node
- Arity or branching factor is the maximum number of children for any node
We were also introduced to a specific kind of tree which is called the Binary Tree which looks like:
Distinctive factors that make the binary tree special is that..
- Binary Trees is a tree with branching factor of 2. Which means that each node has a maximum number of 2 children.
- The children in a binary tree are called left and right child
- Binary Search Trees have a specific property which is that for evener node, its value is greater than all values in its left subtree and less than all values in its right subtree.
- It's good to note that each subtree as well is a BST.
- For example, in the diagram above, all of the nodes on the left child side of 68 will always be less than the nodes values on the right child side of 68 and the pattern still continues as you keep going down the subtree. For example, look at the bottom of the subtree of the node 11. -22 is less than 2 which means the left side is always less than the right side.
Through out the labs, we have worked on some recursive methods that calls on trees that gets a better idea of how they work. Here's an example:
(Will insert pictures later when I get on my CDF account)
You can note that the base case is mostly when there is no children (if self.left == None and self.right == None) which always occurs at the very bottom of the tree.
I think I still need to review this concept as its difficult to wrap my head around but doing the labs really do help practising the concept lectured in class. I really hope the TA strike comes to an end soon as it's my main source of understanding computer science concepts better and its where everything starts to make sense with my TAs help even for CSC165... but other than that, ill try my best to understand it on my own and will try my best on the next test...............ha ha... anyway Happy Slogging and good luck on Test 2 everyone! :)
Saturday 28 February 2015
Week 7 - Object Oriented Programming
For this week, i'd like to indicate that i'd want my Object Oriented Programming SLOG that i've previously written to be marked which is linked here.
In addition to that post, i'd like to add more details and go into depth into the concept of OOP. I've gotten positive feedback that my post was very informative and useful but i'd like to demonstrate these definitions into examples that we have come across throughout the course to get an idea of what it's really talking about and to help those who learn through examples instead of merely memorizing the definition, I know I do.
I will show all of these examples based off of our assignment with Subtract Square, as you all know was our Assignment 1 which was a very good exercise to practice these new concepts in OOP.
So firstly, in Subtract Square, we have encountered many Classes which is defined in my previous post.
Examples of Classes in our assignment are shown in the General Classes that we had to make for the game followed by its docstring that informs us what types, methods..etc are in this particular class, such as:
class GameView:
'''
A game view for a two-player, sequential move, zero-
sum, perfect-information game.
'''
class Strategy:
'''Interface to suggest moves for a GameState.
Must be subclassed to a concrete strategy. Our
intention is to provide a uniform interface for
functions that suggest moves.
'''
class GameState:
'''(Insert docstring of all the methods in this class...
you get the idea)
'''
As stated in the previous post, these classes contain methods and also __init__, __str___, __repr__ etc and whatever relevant methods the programmer wishes to include into this class.
The second thing we've encountered in Subtract Square that is an OOP is Inheritance (Refer to previous post for the definition). We encountered this in Subtract Square when we were writing specific methods of Subtract Square in its individual Subclass.
Here's an example of how Inheritance and Subclasses came into play in our assignment:
We had to make a subclass for the general class because the general class is vague enough that we have to refer to a subclass for specific games, situations, etc. Like our assignment, we made a general class of any particular Game, but what if we wanted to play a specific game? We use Subclasses because every game has different rules and in these subclasses we can use inheritance or override these methods to correspond to the specific game we wanted to play, in this case Subtract Square:
from game_state import GameState
from subtract_square_move import SubstractSquareMove
from math import sqrt
from random import Randint
#This is a crucial step, not importing causes Errors and will not be
#able to inherit from your general class if you did not import it
class SubstractSquareState(GameState):
#General structure of subclass referred to previous post
#"class SubclassName(ClassName):"
'''The state of a Subtract Square game
current_total: int --- total to be subtracted from
'''
So above shows an example of how we created a Subclass in our Assignment Subtract Square. Next is how does this Subclass use Inheritance. Inheritance can be represented in the __init__ method such as so:
def __init__(self, p, interactive=False, current_total=0):
'''(SubstractSquareState, int, str) -> NoneType
(insert docstring here)
'''
GameState.__init__(self, p)
#Notice that I cut out most of the code in __init__
#I just wanted to emphasize the Inheritance part of this code
So the code above that is in the Subclass SubtractSquareState shows inheritance in its __init__method. In this example, it is inheriting GameState and also adding another argument 'p'. This causes the Subclass to inherit everything the general class has but also adding any argument the programmer feels is appropriate for this specific game that is not in the general class because it is not general enough for each game to use.
I hope these examples are relatable and explain these major concepts of OOP that we've come across in this class. If you have any further suggestions, commentary, or opinions, feel free to comment. Also refer back to my post which is linked at the beginning of this post to get the general idea and definitions of these concepts. Happy Programming Sloggers!
In addition to that post, i'd like to add more details and go into depth into the concept of OOP. I've gotten positive feedback that my post was very informative and useful but i'd like to demonstrate these definitions into examples that we have come across throughout the course to get an idea of what it's really talking about and to help those who learn through examples instead of merely memorizing the definition, I know I do.
I will show all of these examples based off of our assignment with Subtract Square, as you all know was our Assignment 1 which was a very good exercise to practice these new concepts in OOP.
So firstly, in Subtract Square, we have encountered many Classes which is defined in my previous post.
Examples of Classes in our assignment are shown in the General Classes that we had to make for the game followed by its docstring that informs us what types, methods..etc are in this particular class, such as:
class GameView:
'''
A game view for a two-player, sequential move, zero-
sum, perfect-information game.
'''
class Strategy:
'''Interface to suggest moves for a GameState.
Must be subclassed to a concrete strategy. Our
intention is to provide a uniform interface for
functions that suggest moves.
'''
class GameState:
'''(Insert docstring of all the methods in this class...
you get the idea)
'''
As stated in the previous post, these classes contain methods and also __init__, __str___, __repr__ etc and whatever relevant methods the programmer wishes to include into this class.
The second thing we've encountered in Subtract Square that is an OOP is Inheritance (Refer to previous post for the definition). We encountered this in Subtract Square when we were writing specific methods of Subtract Square in its individual Subclass.
Here's an example of how Inheritance and Subclasses came into play in our assignment:
We had to make a subclass for the general class because the general class is vague enough that we have to refer to a subclass for specific games, situations, etc. Like our assignment, we made a general class of any particular Game, but what if we wanted to play a specific game? We use Subclasses because every game has different rules and in these subclasses we can use inheritance or override these methods to correspond to the specific game we wanted to play, in this case Subtract Square:
from game_state import GameState
from subtract_square_move import SubstractSquareMove
from math import sqrt
from random import Randint
#This is a crucial step, not importing causes Errors and will not be
#able to inherit from your general class if you did not import it
class SubstractSquareState(GameState):
#General structure of subclass referred to previous post
#"class SubclassName(ClassName):"
'''The state of a Subtract Square game
current_total: int --- total to be subtracted from
'''
So above shows an example of how we created a Subclass in our Assignment Subtract Square. Next is how does this Subclass use Inheritance. Inheritance can be represented in the __init__ method such as so:
def __init__(self, p, interactive=False, current_total=0):
'''(SubstractSquareState, int, str) -> NoneType
(insert docstring here)
'''
GameState.__init__(self, p)
#Notice that I cut out most of the code in __init__
#I just wanted to emphasize the Inheritance part of this code
So the code above that is in the Subclass SubtractSquareState shows inheritance in its __init__method. In this example, it is inheriting GameState and also adding another argument 'p'. This causes the Subclass to inherit everything the general class has but also adding any argument the programmer feels is appropriate for this specific game that is not in the general class because it is not general enough for each game to use.
I hope these examples are relatable and explain these major concepts of OOP that we've come across in this class. If you have any further suggestions, commentary, or opinions, feel free to comment. Also refer back to my post which is linked at the beginning of this post to get the general idea and definitions of these concepts. Happy Programming Sloggers!
Thursday 12 February 2015
OOP, there it is! OOP, there it is!
(Haha, clever name I know, trying to make SLOGs a little more interesting... failed. Anyway, if you didn't get it.. forget it.)
Disclaimer: I'm lame, I know.
So far under the OOP umbrella that we have learned, we learned the concepts of defining classes and subclasses, using inheritance...etc which are the basic concepts before you write any code. The key concepts that we covered thus far are:
"""Class docstring
"""
#followed by methods your class wants to cover as well as __init__, __str__, __repr__... etc
""" Subclass doctstring, don't forget to mention that
it is inherited"""
def __init__(self, attribute, attribute):
"""
"""
ClassName.__init__(self, attribute, attribute)
#and assign anything else you need in this
subclass that is not in the superclass
I think these are the two main concepts of Object Oriented Programming that we have covered so far. We've worked with a lot of problem solving involving these concepts and had thorough practice in them. Also, I think going over the assignment and doing all the labs were a great practice in understanding these concepts! Also, this website has helped clarify any confusion I had with OOP and also looking back at the Proff's slides and hope this will help you as well. (Link here!) Cheers!
Edit: Here is a continuation of this post if you want to see these concepts come into play in problems that we've encountered in class to get a better grasp of these definitions and ideas. (Link to Examples Here!)
Disclaimer: I'm lame, I know.
Anyway, on to the topic. This week we're summarizing what we know about Object-Oriented Programming (OOP) concepts. First of all, OOP is a programming language model organized around objects rather than "actions" and data rather than logic. (Definition from here). For those who want to clarify what it is. Basically, the difference is that in logic, it takes an input, processes it and produces an output of data. The material we've mostly covered so far in CSC148 is all about OOP. Where we take objects and we want to manipulate them rather than the logic manipulating them. The object represents the state and behaviour.
So far under the OOP umbrella that we have learned, we learned the concepts of defining classes and subclasses, using inheritance...etc which are the basic concepts before you write any code. The key concepts that we covered thus far are:
- Class: which is an object that defines a set of attributes that characterize any object of the class
- Class statement is written as:
"""Class docstring
"""
#followed by methods your class wants to cover as well as __init__, __str__, __repr__... etc
- We also had some practice in creating instance objects, and accessing attributes in classes
- Inheritance: allows us to add extensions of existing classes to a new class which is the Subclass
- The subclass is the child class where as the existing class (as described above) is the parent class
- This is useful when you want to make a general class and apply it to different circumstances of that class. For example, if you want to make a general class Shape and make subclasses of specific shapes such as Square, Rectangle ..etc. This could be done by using inheritance and/or over-riding methods in the class itself.
- Inheritance in subclasses look like this:
""" Subclass doctstring, don't forget to mention that
it is inherited"""
def __init__(self, attribute, attribute):
"""
"""
ClassName.__init__(self, attribute, attribute)
#and assign anything else you need in this
subclass that is not in the superclass
I think these are the two main concepts of Object Oriented Programming that we have covered so far. We've worked with a lot of problem solving involving these concepts and had thorough practice in them. Also, I think going over the assignment and doing all the labs were a great practice in understanding these concepts! Also, this website has helped clarify any confusion I had with OOP and also looking back at the Proff's slides and hope this will help you as well. (Link here!) Cheers!
Edit: Here is a continuation of this post if you want to see these concepts come into play in problems that we've encountered in class to get a better grasp of these definitions and ideas. (Link to Examples Here!)
Subscribe to:
Posts (Atom)