Figured Exercise 5.4 with some help from RosettaCode.org