problem 18 solution