2015年2月1日星期日

Week 4 SLOG about Recursion

In this week, recursion is a new concept for me, and I think this is hard to understand how it works at first. I usually get wrong way in some problems.But I work it out with some help of TA and I try some exercise in the lab successfully.
    
For example, in this question:

 def   count_elements(L): 
        ’’’(list or non-list) -> int 

        Return 1 if L is a non-list, or number of non-list elements in possibly- nested list L. 

       Assume: L is any Python object. # examples omitted! 
       ’’’ 

       if isinstance(L, list): 
           return sum([count_elements(x) for x in L]) 
       else: # if L is not a list, count it 
           return 1

1.Trace count_elements('smoke')
 The answer is 1 because 'smoke' is a string but not a list.

2.Trace count_elements([2, 1, 3])
 The answer is 3 because [2, 1, 3] is a list and then the elements in the list  are 2, 1, 3 which are integers but not lists. Then it comes out sum[1, 1, 1]  which is 3.

3.Trace count_elements([[2, 1, 3, '[4]’]])
 The answer is 4. In the same way, it goes through the loop again and again and  it comes out sum[1, 1, 1, 1] which is 4.

4.Trace count_elements([7, [2, 1, 3], 9, [3, 2, 4]])
 The answer is 8 comes from sum[1. 1. 1. 1. 1. 1. 1. 1]


Overall, solving the recursion problem is going through the loop. And the best way to work it out is write down all things step by step.

2015年1月25日星期日

Week 3: Why geeks should write?

    Geeks indicate the group of people who have outstanding work on their career but are not good at communicating with others. Therefore, they always have some excellent ideas but they do not share them with others because of their poor communication skills. So writing down their thoughts is a nice way for geeks to express themselves.
    Nowadays, writing something down is the direct way to record someone's ideas. After all, writing is not required to any communication skills so that geeks can write down what they want to express, what they have thought and what they think it valuable without considering the problems in social chat. And it is also beneficial to people because others can learn something from geeks through reading what geeks wrote, which is a form of transmission of knowledge.
   In additional, writing down something is the safe way to save so that we won't lose it easily. For example, people can record their daily experience or some ideas on blog, and then they save what they write on the internet. Also, they can review it conveniently whenever they want. For geeks, it is a recommend method to record something valuable, which helps their future work.
   In a word, geeks should write rather than they keep in silent and do nothing.