This belongs in combinatorics or iterables (if there isn't an equivalent there already).