Built brute force method for Q2 P2, but too slow