Solving problem 39