2015年4月5日星期日

Impression of Week 10

Week 10

Unit test and Assert statement

Unit test is used to test each small single cases of a function. Remind it can just represents one single case, so even the function passes some unit tests, it can still not be guaranteed that the function works well without bugs. However, if one choose a lot of unit tests which can conclude all cases that the function may face, passing all unit tests means the function is quite solid.


Assert statement is  an another way to check codes. In the process of writing code, a lot of different errors may occur while we do not know which part exactly is wrong. Thus, we may use print() method to print out the value of everything and check if they meet our expectation. However, the adding of print() is quite time consuming as we still need to remove them after we find out the solve the problem. A good alternative is assertions by implementing assert statements.

2015年3月16日星期一

Impression of week 7,8,9

Week 7

Binary tree is the main topic. The concept is not hard to understand.

*After Test 2 I found I miss one important idea called traversal, which means visiting the nodes to do something at each. There are three types of traversal, in order, pre order and post order. I found an really amazing image to conclude these three:

The order of number is exactly the order nodes are visited. 

BST

A binary search tree is a binary tree with specific order of nodes. For every node, its value is greater than all values in its left subtree and less than all values in its right subtree


About recursion

Among the three given topics, I think recursion is the most difficult idea (especially when combine with other topics like trees)that I am still not fully comfortable with.

Recursion requires you to have a different way of thinking, one cannot find the solution in a straight way (because you do not know how many time it would recurse, and what it the situation of it.)

Recursion needs us to change our thinking mode. Things go recursively with a base case and recursive cases. Everything would go through in recursive case, and finally finish in base case. All base case would gather together to form the whole function. The change from straight solution to make it in a base case and recursive cases is where the difficulty stands.


Week 8

The topic this week is linked list, which is far complicate than I used to think.

I used to think linked list are trees that have just one child. Since we have learnt Binary search tree, which children could be more than one, and must be in certain order, linked list should not be harder.

However, linked list has more elements. From the initialize method of linked list, we can find it has a value (which is the value of certain node ) and a nxt (refers to other similar objects). Moreover, it has a wrapper class which assist to track the information about the entire list. It has a front, a back and stores the size of a linked list.

Week 9

More on BTNode

A new BTNode is introduced which is called BST (binary search tree). Compare to BTNode, BST has a strict limitation in terms of nodes. All children nodes on the left side of parent node must be smaller than the parent node, and the one on the right must be larger than the parent node.



2015年2月26日星期四

Summary of Object-Oriented Programming concepts

In fact, this topic is mentioned in the beginning of the slog since the idea of object-oriented programming is one of the first concepts introduced in CSC148 and can concludes the difference between CSC148 and CSC108.

In CSC148, the detailed code is never emphasized. Recall what we have learnt so fat, the class (how to build a class, the subclass, inheritance, exception, etc.) and recursion and tree. These are all general ideas telling you the big ways to achieve one thing. CSC108, on the other hand, focus on the basic codes and concepts like list, dictionary and some statement like for, while , if, etc.

No wonder these basic elements are extremely important as you cannot make a move without knowing these thing, but only knowing these thing would limit your sight. You may simply lost your way in a large program. The idea of Object-Oriented Programming helps you to stand higher and see further.

However, the disadvantage of this concept is that, students may feel difficult to actually write the code of sth. especially for those whose skill of coding is not really solid. I think more basic exercises is still needed in CSC148, rather than just focus on the big idea.

2015年2月22日星期日

Reading week === Some idea about assignment 2

Since it is reading week and no class is in progress, I do spend some time working on assignment 2. Personally I think the biggest difference between assignment 1 and 2 is that subtract square is a text-base game while tippy is a graphic-base game. Of course the computer cannot understand the graph of board or how those circle and cross on the board form shapes. Then that means we need to work to "translate" the graph to the text.

My idea of that is to use number representing each block. For example, a 3 x 3 block may looks like this:
 and the program may interpret each block as a number:

so when the player want to choose a block to occupy, he or she actually choose a number from 1 to 9 to represent the block.

Then mechanism of deciding winner goes a little bit more complicate. There are generally four patterns of winning situation:

OOX    n, n+1
XOO    n+size+1, n+size+2
XXX    

OXX    n
OOX    n+size, n+size+1
XOX    n+2*size+1

XOX    n
OOX    n+size-1, n+size
OXX    n+2size-1

XOO    n, n+1
OOX    n+size-1, n+size

XXX

* size is a variable means the length of each row.

Imagine this, player 1 choose a move for four times, all his or her moves are recorded in a list, we sort the list and see if the four numbers match the pattern of the four numbers I listed above. However, we need to avoid the situation which like this:

XOO   
XXO

OXX   

It also follows the pattern (first block = n, second block = n+1, third block = n+size+1, fourth block = n+size+2), and from this we see that the first block cannot not be larger than n*size-2, in other words:
a//size or (a+1)//size would return a False.

These things are just conceptual level, but I think it is practical and is able to change to code.


2015年2月8日星期日

About week 5

Trace Recursion, write recursion.

The term test 1 has ended. Some potential problems that I have not paid enough attention is showed in the test.

Firstly, although I know what does exception means and how to use it, I do not realize when using it appropriately. I still let my intuition goes like

print('This does not work')
rather than
raise Exception('This does not work')

Also, I sometimes forget to write code “raise” before Exception or NotImplementError .


I have somehow be more familiar with the idea of recursion, specifically where to  put the function in the code. So far I managed to do all the assignments and labs relate to recursion, and I want more questions for exercise.

2015年1月31日星期六

About Week 4

We goes to recursion in week 4. Somehow I think I gradually follow the class of CSC148. 148 focus on general idea and does not do as much practice as 108. Yes, we do have labs, but I do not think I works as well as PCRS.

Recursion, in short, means use the definition itself to define the definition. It has certain pattern:

def mm(L):
    """
    (int or arbitrarily nested list of int) -> int
    
    Mystery method.  Exactly the same as sum_list,
    except for the last line
    """
    
    if isinstance(L, list):
        return sum( [count(x) for x in L] )
    else:
        return 0

Here the isinstance(X, type) is always there because we need to decide whether to recurs L or end L. By this way we peel the L like an onion until it becomes the very basic element. In the example above L may originally be a list, and after recurs L again and again, the lists would be broken and separated into small elements.


2015年1月24日星期六

About Assignment 1

I have made the game itself. But still not work well with the idea of class, subclass and so on. Need to study and spend more time on it.