solution to number 9 and a brute force approach to 10 that takes forever