modify the recursive calculation so that it can handle the right boundary
properly; add the comparsion between recursive and direction calculations;
everything seems OK