For this challenge you are going to make a function (your function may be a complete program) that takes a list as input and returns a permutation of that list. Your function must obey the following requirements.
It must be deterministic.
Composing your function with itself a variable number of times should be capable of getting a list to any of its permutations.
This is a code-golf question so answers will be scored in bytes, with less bytes being better.
Further rules
You may take any type of list, (
[Integer]
,[String]
,[[Integer]]
) as long as it- Can be non empty
- Can contain distinct objects with at least 16 possible values. (You can't use a Haskell
[()]
and claim your function isid
) - Can contain duplicate objects (no sets)
You may write a program or a function, but must obey standard IO.
S_n
is only cyclic forn<3
\$\endgroup\$ – Leaky Nun Jul 14 '17 at 18:51next_permutation
function. \$\endgroup\$ – Peter Taylor Jul 14 '17 at 18:51