Brute force solution for Problem 14. Must do better.