Because of some problems, I need to divide the permutation represented by a list into several single loop lists.
For example, for list {4, 3, 2, 1, 7, 6, 5}
, it can be divided into two single loops {4, 3, 2, 1}
and { 7, 6, 5}
, where {4, 3, 2, 1}
and { 7, 6, 5}
are continuous single loops (the single cycle in the positive direction and the single cycle in the opposite direction all meet the requirements).
PermutationCycles[{4, 3, 2, 1, 7, 6, 5}]
But the results of the above code do not meet the requirements, what should I do to achieve this requirement delicately?
Other examples for testing:
{3, 2, 1, 7, 6, 4, 5}
(*{{3,2,1},{7,6},{4,5}}*)