Skip to main content
edited tags
Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Tweeted twitter.com/StackMma/status/1291524520235474944
Became Hot Network Question
added 97 characters in body
Source Link

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}}*)

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?

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}}*)
Source Link

How to divide a list into several single loops

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?