Generate#
To use the generator of permutation, import it as
import symmetria
...
permutations = symmetria.generate(algorithm="lexicographic", degree=3)
The API of the method is given as following:
- symmetria.generate(degree: int, algorithm: str = 'lexicographic') Generator[Permutation, None, None][source]#
Generate all the permutations of the degree based on the chosen algorithm.
The method generates all the permutations of the given degree using the specified algorithm.
- Parameters:
degree (int) – The degree of the permutations to be generated. Must be a non-zero positive integer.
algorithm (str, optional) – The algorithm to use for generating permutations. Default is “lexicographic”.
- Returns:
A generator yielding permutations.
- Return type:
Generator[“Permutation”, None, None]
- Raises:
ValueError – If the algorithm is not supported or the degree is invalid.
- Examples:
>>> import symmetria ... >>> permutations = symmetria.generate(degree=3, algorithm="lexicographic") >>> for permutation in permutations: ... permutation Permutation(1, 2, 3) Permutation(1, 3, 2) Permutation(2, 1, 3) Permutation(2, 3, 1) Permutation(3, 1, 2) Permutation(3, 2, 1)