Finished book problem 3.5.