Solving problem 18