Solve Problem 30 by brute force