Doing some algorithm design and analysis in Python