Completed brute force implementation