Solution to 47 (brute force, inefficient)