finished brute force solution