refactor combinatorics.py