Slightly better solution to 9.

The solution to 9 is obviously still brute-force, but now it is slightly less terrible.