brute force implementation