fast brute force algorithm