SymPy | Permutation.runs() in Python

SymPy | Permutation.runs() in Python

In SymPy, the Permutation class provides the runs() method to return all the runs (also known as increasing subsequences) of a permutation.

A run in a permutation is a maximal contiguous increasing subsequence. For example, in the permutation [3, 4, 5, 0, 1, 2], the runs are [3, 4, 5] and [0, 1, 2].

Syntax:

Permutation.runs() 

Returns:

  • list of lists : Each inner list is a run (an increasing subsequence) of the permutation.

Example:

Let's take a look at an example to understand its usage:

from sympy.combinatorics import Permutation # Create a permutation p = Permutation(3, 4, 5, 0, 1, 2) # Get the runs of the permutation runs = p.runs() print(runs) # Output: [[0, 1, 2], [3, 4, 5]] 

In this example, the permutation has two runs: [0, 1, 2] and [3, 4, 5]. The result is returned as a list of these runs. The runs represent the indices of elements in the permutation rather than the elements themselves.


More Tags

intellij-plugin sparse-checkout css-loader oracle-apps sqoop bower int spring-hateoas fixed-header-tables n-ary-tree

More Programming Guides

Other Guides

More Programming Examples