Brute force solution to Problem 16