Brute force attempt at problem 12.