Problem 42 solution