Solved pe 31
code from a stanford lecture on recursion