I have been checking it over the net and asking friends, since I am very new to coding. I find all these posts about writing all possible permutations on n letters. I am not looking for that.
What I am trying to achieve is given an array of integers, I want to turn that into a permutation as follows. Say X is an array of integers;
X= { 3, 4, 1, 2, 5}
Now people familiar with permutation groups (or symmetric group) would know that there is cycle notation for any permutation. I want to see X as some function that assigns values as follow;
1 --> 3
2 --> 4
3 --> 1
4 --> 2
5 --> 5
In a way, if the above function is the permutation sigma, then we have sigma(1)= 1st entry in X, sigma(2)= 2nd entry in X and so on.
And finally, I need to count how many loops there will be in this permutation, or number of cycles in a cycle notation. Again for the example above, we have
1 --> 3 --> 1 (So this is a one loop)
2 --> 4 --> 2 (Another loop)
5 --> 5 (This is also a loop)
So it should also tell me that X has 3 loops in this case.
This might be a detailed question, but any any, tiny bit of help is appreciated. Thank you all sooo much!