Problem 38 solution