Solved Problem 18, Python

This is about six times faster than the Scheme version.