Ported a project euler problem to Python3 with improvements