Tiernan's Algorithm implemented in Python