Implements problem 3 of chapter one