Problem 24: brute force + Python = an easy time