Brute force problem 3 solution