problem 9 naive solution
problem 9 optimized solution