Solution problem 14 (brute force)