Implements problem 7 in chapter one