Problem 12: brute force solution