THE TASK
DEFINITIONS
Consider the points {1,2,3,4,5} and all their permutations. We can find the total number of possible permutations of these 5 points by a simple trick: Imaging filling 5 slots with these points, the first slot will have 5 possible numbers, the second 4 (as one has been used to fill the first slot) the third 3 and so on. Thus the total number of Permutations is 5*4*3*2*1; this would be 5! permutations or 120 permutations. We can think of this as the symmetric group S5, and then Symmetric Group Sn would have n! or (n*n-1*n-2...*1)
permutations.
An "even" permutation is one where there is an even number of even length cycles. It is easiest to understand when written in cyclic notation, for example (1 2 3)(4 5)
permutes 1->2->3->1
and 4->5->4
and has one 3 length cycle (1 2 3)
and one 2 length cycle (4 5)
. When classifying a permutation as odd or even we ignore odd length cycles and say that this permutation [(1 2 3)(4 5)
] is odd as it has an odd number {1} of even length cycles.
Even examples:
(1)(2 3)(4 5)
= two 2 length cycle | EVEN |(1 2 3 4 5)
= no even length cycles | EVEN | * note that if no even length cycles are present then the permutation is even.
Odd Examples:
(1 2)(3 4 5)
= one 2 length cycle | ODD |(1)(2 3 4 5)
= one 4 length cycle | ODD |
As exactly half of the permutations in any Symmetric Group are even we can call the even group the Alternating Group N, So as S5 = 120 A5 = 60 permutations.
NOTATION
Permutations should, for this at least, be written in cyclic notation where each cycle is in different parenthesis and each cycle goes in ascending order. For example (1 2 3 4 5)
not (3 4 5 1 2)
. And for cycles with a single number, such as: (1)(2 3 4)(5)
the single / fixed points can be excluded meaning (1)(2 3 4)(5) = (2 3 4)
. But the identity {the point where all points are fixed (1)(2)(3)(4)(5)
} should be written as ()
just to represent it.
THE CHALLENGE
I would like you to, in as little code possible, take any positive integer as an input {1,2,3,4...} and display all the permutations of the Alternating Group An where n is the input / all the even permutations of Sn. For example:
Input = 3
()
(1 2 3)
(1 3 2)
and
Input = 4
()
(1 2)(3 4)
(1 3)(2 4)
(1 4)(2 3)
(1 2 3)
(1 3 2)
(1 2 4)
(1 4 2)
(1 3 4)
(1 4 3)
(2 3 4)
(2 4 3)
And as with in the examples I would like for all cycles of one length to be elided, and as for the identity: outputs of nothing,
()
{not only brackets but with whatever you are using to show different permutations} or id
are acceptable.
EXTRA READING
You can find more information here:
GOOD LUCK
And as this is codegolf whoever can print the Alternating Group An's permutations in the shortest bytes wins.
[[1, 2], [3, 4]]
instead of(1 2)(3 4)
? \$\endgroup\$(2 3 1 4)
in ascending order? Do you mean we should just put the smallest element at the front? \$\endgroup\$(2 3 1 4)
does2->3->1->4->2
it can be written(1 4 2 3)
with its smallest element first \$\endgroup\$