code for problem 3
Wrote problem 4 and I like the solution.