Converted problem 96 solution to Python, and significantly upgraded it.