Solving problem 9 ith limited brute force