Homework 3, Problem 7 in my Algorithms class