successful solution (brute force) to problem 30