prob 10 solution - slow, need to rework