Adding problem 5 complete solution