I have asked this question on math.stackexchange.com but received no response; hoping someone on here can help.
Suppose a function $f$, representing what I call a "dynamic transposition cipher" taking one string of text $str$ as input, is defined so that it outputs another string of text $res$ which is the transposed characters of $str$ according to the following algorithm:
- Let $i_1 = 1$, $i_2 = $ the number of characters in $str$, and $res = ""$ (empty string)
While $i_2 - i_1 > 1$:
a. Append the character $str[i_1]$ to $res$
b. Append the character $str[i_2]$ to $res$
c. Increment $i_1$ by $1$
d. Decrement $i_2$ by $1$
If $i_1 = i_2$, then append the character $str[i_1]$ to $res$; otherwise, append the characters $str[i_1]$ followed by $str[i_2]$ to $res$.
- Return $res$
Assume that string indices begin at one, i.e. "ABC"$[1] = $ "A" and that each character of $str$ is unique.
For example, $f($"ABCDEF"$)$ would equal "AFBECD", and $f($"AFBECD"$)$ would equal "ADFCBE". We can keep iterating $f \circ f \circ f(x)$, yielding "AEDBFC", "ACEFDB", and finally "ABCDEF", which was our original input. All in all, for any string $str$ of 5 characters, $f(str)$ = 4, since it takes four iterations including the original string.
Let $g(n)$ represent the number of iterations required to transpose a string of $n$ characters back into itself according to $f$.
Following this formula for strings of 1 through 10 characters, there is unusual variation in the number of iterations required: $g(2) = 2$, $g(3) = 3$, $g(4) = 4$, $g(5) = 4$, $g(6) = 6$, $g(7) = 7$, $g(8) = 5$, $g(9) = 5$, and $g(10) = 10$. I have calculated these values up to $g(30)$: $g(28) = 21$, $g(29) = 10$, and $g(30) = 30$.
Plotting these discrete points, we can find several linear functions which collectively fit some of the points: $y = x$ fits some, $y = 0.5x + 1.5$ fits others, while $y = 0.25x + 2.5$ fits still others, while there are many more data pairs not accounted for. I am not noticing much of a pattern that holds consistently besides $y=x$.
What would be a definition of $g(n) \space | \space n \in \Bbb I, n > 0$?