Script to help solve combinatorics problem