Inspired by this question.
Challenge
Let L
be a list of n
distinct elements. Let P
be the set of all (unordered) pairs of positions in P. Let R
be a result of applying a pair-swap operation on L
by every pair in P
in any order.
Example:
L = [1, 7, 8]
P = {(1, 2), (0, 1), (0, 2)}
L = [1, 7, 8] -> [1, 8, 7] -> [8, 1, 7] -> [7, 1, 8] = R
Your task is to output every possible R
(without multiplicity) in any order.
Constraints
L
can have any length, including 0 and 1- All elements of
L
are guaranteed to be distinct
Examples
- Input:
[1, 5]
Output:[5, 1]
- Input:
[0, 1, 2, 3]
Output:
[3, 2, 1, 0]
[1, 0, 3, 2]
[2, 3, 0, 1]
[3, 0, 2, 1]
[1, 2, 0, 3]
[1, 3, 2, 0]
[2, 0, 1, 3]
[2, 1, 3, 0]
[0, 2, 3, 1]
[3, 1, 0, 2]
[0, 3, 1, 2]
[0, 1, 2, 3]
- Input:
[150]
Output:[150]
Rules
- this is
code-golf
challenge, so the shortest code wins - standard rules apply for your answer with default I/O rules
- default Loopholes are forbidden.
Œ!
produces was incorrect. \$\endgroup\$