problem 3, brute force method