[Question]
  [
This challenge initially appeared in [this challenge](https://codegolf.stackexchange.com/questions/141315/)  as a an extra brain teaser. I am posting it with permission from the original author so that we can have a formal competition.
---
Your task here will be to implement a function1 that forms a permutation on the positive integers. This means that each positive integer should be the output of calling the function with exactly one positive integer.
In the earlier challenge we calculated the odd probability for such sequences. We defined it as so:
If we have a function \$f\$ the probability of a number being odd will be defined as the limit of ratio odd members of the set to the size of the set \$f\{1\dots n\}\$ as \$n\$ tends towards infinity.
$$\lim\_{n\rightarrow \infty}\dfrac{\left|\{x : x \in \{1\dots n\}, \mathrm{odd}(f(x))\}\right|}{n}$$
Your task is to write a function with no defined odd probability. That is a function \$f\$ for which the above limit does not converge.
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so answers will be scored in bytes with less bytes being better.
---
1: Here function will mean program or function. It is just a piece of code that takes input and produces output.
  
[Answer]
# JavaScript (ES7), ~~33~~ 29 bytes
This is [A307485](https://oeis.org/A307485): one odd, two even, four odd, eight even, etc.
```
n=>n-~n-(4<<Math.log2(n))/3|0
```
[Try it online!](https://tio.run/##Fcs5DoAgEADA3ldsCTEoHp3gD3wEUfCI2TVobDy@jtJNM4s5zd77eTsE0mCD0wF1i@JFwWqlOnNM2UpjyZDzvLplcOQZgoaiAQQFhZQ/0pTDlQD0hDutNg7mYmmSJ3w "JavaScript (Node.js) – Try It Online")
For \$n\in\mathbb{N}^\*\$, this is equivalent to:
$$a(n)=2n+1-\left\lceil\frac{2^{\lfloor log\_2 n\rfloor+2}}{3}\right\rceil$$
It produces the sequence:
```
1
2 4
3 5 7 9
6 8 10 12 14 16 18 20
...
```
The ratio of odd values is 'bouncing' ad infinitum between \$1/3\$ and \$2/3\$, more and more slowly:
[![graph](https://i.stack.imgur.com/cYEZ6.png)](https://i.stack.imgur.com/cYEZ6.png)
[Answer]
# [sed](https://www.gnu.org/software/sed/) -E, ~~20~~ 17 bytes
```
s/\B(.)(.*)/\2\1/
```
[Try it online!](https://tio.run/##K05N0U3PK/3/v1g/xklDT1NDT0tTP8YoxlD//39TI3Nji3/5BSWZ@XnF/3VdAQ "sed – Try It Online")
*Saved 3 bytes as per user41805's suggestion.*
This takes the input number and moves the 2nd digit (from the left) to the end of the number (the one's place).
The numbers from 1 to 10*n* are just rearranged, so the proportion of odd numbers for inputs up to 10*n* is 0.5.
All the numbers from 10*n*+1 to 10*n*+10*n*-1-1 map to even numbers, so the proportion of odd numbers for inputs up to 10*n*+10*n*-1 is
$$\frac{10^n/2+1}{10^n+10^{n-1}}=\frac{5+10^{-(n-1)}}{11},$$
which approaches 5/11 as *n* approaches infinity.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~18~~ ~~17~~ 16 bytes
```
:"vtn@W:2e+!h]G)
```
[**Try it online!**](https://tio.run/##y00syfn/30qprCTPIdzKKFVbMSPWXfP/fyNDAA)
This produces the following permutation of the positive integers:
```
1 2 3 5 4 6 7 9 11 13 8 10 12 14 15 17 19 21 23 25 27 29 16 18 20 22 24 26 28 30 ...
```
The pattern is easier to see if the sequence is arranged as follows (read top to down, then left to right):
```
1
2
3   5
4   6
7   9 11 13
8  10 12 14
15 17 19 21 23 25 27 29
16 18 20 22 24 26 28 30
...
```
It's clear that the cumulative proportion of odd values has limit superior `2/3` and limit inferior `1/2`. Or see the proportion graphically at [**MATL Online!**](https://matl.io/?code=%3A%22vtn%40W%3A2e%2B%21h%5DoYstf%2FXG+&inputs=10%0A%25+Let+the+input+number+be+n.+Then+the+code+produces+the+first+2%5E%28n%2B1%29+terms+of+the+sequence%2C+and+plots+its+cumulative+odd+ratio&version=22.2.0)
### Explanation
The code produces a longer sequence than needed (with length exponential in the input number), and then outputs the term specified by the input.
```
:       % Implicit input, n. Push range [1 2 ... n]
"       % For each k in [1 2 ... n]
  v     %   Concatenate stack vertically. This is only useful in the first
        %   iteration, to produce the empty array [], which will later be 
        %   extended with terms of the sequence
  tn    %   Duplicate sequence so far. Push its number of elements, say m
  @W:   %   Push range [1 2 3 ... 2^k]
  2e    %   Arrange as a two-row matrix in column-major order. Gives
        %   [1 3 5 ... 2^k-1;
        %    2 4 6 ... 2^k]
  +     %   Add, element-wise. Gives
        %   [m+1 m+3 m+5 ... m+2^k-1;
        %    m+2 m+4 m+6 ... m+2^k]
  !h    %   Transpose, then concatenate into a row vector. This extends the
        %   sequence. The transpose is needed so that, when concatenating,
        %   the terms are included in the correct order
]       % End
G)      % Take the n-th entry. Implicit display
```
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~8~~ 4 bytes
```
⌽1⌽⍞
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qKM97f@jnr2GQPyodx6I/z@Ny8jE3NjUzIgrjcvSwMAQSBkCAA "APL (Dyalog Extended) – Try It Online")
Based on [xnor's idea](https://codegolf.stackexchange.com/a/200948/78410) to keep the first digit and reverse the rest. A full program that takes the input from STDIN as a string, rotates left once (`1⌽`), reverses (`⌽`), and prints to STDOUT.
---
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), 8 bytes
```
⊥1,1⌽1↓⊤
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn//1HXUkMdw0c9ew0ftU1@1LXkf9qjtgmPevse9U319H/U1XxovfGjtolAXnCQM5AM8fAM/p92aIXCo97NxoYA "APL (Dyalog Extended) – Try It Online")
Generates a sequence that is very similar to [Luis Mendo's MATL answer](https://codegolf.stackexchange.com/a/200923/78410):
```
1
2
3
4 6
5 7
8 10 12 14
9 11 13 15
16 18 20 22 24 26 28 30
17 19 21 23 25 27 29 31
...
```
### How it works
```
⊥1,1⌽1↓⊤
       ⊤  ⍝ Convert to binary digits
     1↓   ⍝ Remove the leading 1
   1⌽     ⍝ Rotate left once; move 2nd bit to last
 1,       ⍝ Add back the leading 1
⊥         ⍝ Convert binary digits to integer
```
[Answer]
# [Haskell](https://www.haskell.org/), 18 bytes
```
f(h:t)=h:reverse t
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00jw6pE0zbDqii1LLWoOFWh5H9uYmaegq1CbmKBr4JGQWlJcEmRT55eml5xRn65pkK0gY6pjqGRMRAbAJkGBqax//8lp@Ukphf/100uKAAA "Haskell – Try It Online")
Based on [Mitchell Spector's idea](https://codegolf.stackexchange.com/a/200926/20260). Leaves the first digit in place and reverses the rest. Input and output are as strings.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~6~~ 5 bytes
```
,V1,`
```
[Try it online!](https://tio.run/##K0otycxLNPz/XyfMUCfh/38DLlMuQyNjIDYAMg0MTAE "Retina – Try It Online") Link includes test cases shamelessly stolen from @xnor. Uses the same suffix reversal algorithm inspired by @MitchellSpector's `sed` answer. Edit: Saved 1 byte thanks to @FryAmTheEggman. Explanation:
```
V`
```
Reverse the matched characters (defaults to matching each line).
```
,
```
Reverse all matches
```
1,
```
Exclude the first character of each match from being reversed. (`^0` also works.)
[Answer]
# [Python](https://docs.python.org/2/), 22 bytes
```
lambda s:s[0]+s[:0:-1]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUaHYqjjaIFa7ONrKwErXMPZ/Wn6RQqZCZp5CtIGOqY6hkTEQGwCZBgamsVZcnAVFmXklCpk6CmkaxSVFGpmamv8B "Python 2 – Try It Online")
Based on [Mitchell Spector's idea](https://codegolf.stackexchange.com/a/200926/20260). Leaves the first digit in place and reverses the rest. Input and output are as strings.
[Answer]
# Pure [Bash](https://www.gnu.org/software/bash/), 27 bytes
```
echo ${1:0:1}${1:2}${1:1:1}
```
[Try it online!](https://tio.run/##S0oszvj/PzU5I19BpdrQysDKsBZEG4FJIKz9//@/oZGxiSkA "Bash – Try It Online")
This uses the same method as my sed answer.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~18~~ 17 bytes
```
(.)(.)(.*)
$1$3$2
```
[Try it online!](https://tio.run/##K0otycxLNPz/X0NPE4y0NLlUDFWMVYz@/zcyNjE1@w8A "Retina – Try It Online")
This is a port of my sed answer (moving the second digit to the far right). I've never programmed in Retina before, so I took a quick look at the language documentation and put this together. I assume that it can be made much shorter using more advanced features of Retina.
Also, if there's any error in the Retina code, please let me know. It does appear to work :) .
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 7 bytes
```
§θ⁰⮌✂θ¹
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMOxxDMvJbVCo1BHwUBT05oLIhqUWpZaVJyqEZyTmZwKkjPUBEr@/29oZGxi@l@3LAcA "Charcoal – Try It Online") Link is to verbose version of code. This is the Charcoal port of the 6-byte Retina 1 answer that I alluded to in my comments to @MitchellSpector's `sed` answer, and then presumably independently discovered by @xnor. I/O as strings (which Charcoal defaults to anyway). Explanation:
```
§θ⁰
```
Print the first character of the input number.
```
⮌✂θ¹
```
Print the remaining characters of the input number, but reversed.
]