make brute force slightly faster for problem 9