slight reformatting of problem 5

needs more tail recursion though