Completed Chapter 2 Problem 7, think I came up with a better solution