brute force optimization source code