Problem 16 solution