Problem 145 JS solution. Brute-force, kind of a hack.