Tuesday, February 25, 2014

Something about recursion


Here is something recursion to print every file path in the root dir, from here.


import os

def printpath(rootDir):

    for lists in os.listdir(rootDir):

    path = os.path.join(rootDir, lists)

    print(path)

    if os.path.isdir(path):

        Test2(path)



And here is some 'formula' for recursion, from Eric Lippert:

Result M(Problem prob) { 
     if (<problem can be solved easily>) 
     return <easy solution>; 
     // The problem cannot be solved easily. 
     Problem smaller1 = <reduce problem to smaller problem> 
     Result result1 = M(smaller1); 
     Problem smaller2 = <reduce problem to smaller problem> 
     Result result2 = M(smaller2); 
     ... 
     Result finalResult = <combine all results of smaller problem to solve large      problem> 
     return finalResult; }

Monday, February 3, 2014

Four stool TOAHModel

It seems that I got some luck for the best i in the four stool TOAHModel.After the programming, I read a little about the algorithm for the solution of the program, which is called Frame–Stewart algorithm.
This and this article is kind of helpful.