i’m new in Haskell. I have to write function that takes list of Integers and returns number of composition needed to recieve identity permutation. Something like that:
permutationOrder :: [Int] -> Int
I’d be grateful for any help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming the list contains the numbers from
0ton-1in some order,gives you the graph of the permutation. From the graph, you can easily compute the order by partitioning it into connected components (corresponding to the cycles the permutation is composed of). The order of a cycle is the number of elements in the cycle. Disjoint cycles commute, that makes it easy to compute the order of a product of disjoint cycles.