Problem 47: Initial solution