Your task is to find out how often you need to "shuffle" a given list with the following operation until you get back the original list.
start with a list:
(1 2 3 4 5 6 7 8 9)
split it into the elements at odd and even indices
(1 3 5 7 9) (2 4 6 8)
concatenate these two list
(1 3 5 7 9 2 4 6 8)
Input: A list
Output: The number of iterations it takes until you get back the original list
Examples
(1 2 3) -> (1 3 2) -> (1 2 3) => 2
(1 2 3 4 3 2 1) -> (1 3 3 1 2 4 2) -> ... => 3
(1 2 3 4 5 6 7 8 9 10) -> ... => 6
(1 2 3 4 5 6 7 8 9 10 11) -> ... => 10
"abab" -> "aabb" -> "abab" => 2
"Hello, World!" -> "Hlo ol!el,Wrd" -> ... => 12
(1 0 1 1 0 0 0 1 1 1) -> ... => 6
(1 0 0 1 1 1 0 0 0 0 1) -> ... => 10
(1 1 1 1 1 1 1) -> (1 1 1 1 1 1 1) => 1
Rules
- You can use lists of any type (that supports at least two distinct values)
- You can assume the the list has at least two elements
- The odd/even indices are determined using 1-based indexing
- You have to apply the operation at least once
- If your language has a built-in for finding fixed points consider adding a non-builtin solution as well
- This is code-golf the shortest solution (per language) wins