Problem 50 - solution