bibliopixel.util.permutation module

bibliopixel.util.permutation.advance_permutation(a, increasing=True, forward=True)[source]

Advance a list of unique, ordered elements in-place, lexicographically increasing or backward, by rightmost or leftmost digit.

Returns False if the permutation wrapped around - i.e. went from lexicographically greatest to least, and True in all other cases.

If the length of the list is N, then this function will repeat values after N! steps, and will return False exactly once.

See also https://stackoverflow.com/a/34325140/43839