[Question]
  [
Given a string as an input (which can be any acceptable/convenient format in your language), implement pendulum encoding. The test cases are split into individual items (which aren't quoted) for a visually appealing explanation.
## How do I do that?
The current **iteration index** starts at `0`.
* If the iteration index is even, append the current item onto the output string.
* If the iteration index is odd, prepend the current item onto the output string.
## An example
```
The input is [a b c d e f g].
Note that the letters a-g are individual one-character strings, to prevent confusion from the iteration index.
N: the iteration index
N:0 Out:      [a]
N:1 Out:    [b a]
N:2 Out:    [b a c]
N:3 Out:  [d b a c]
N:4 Out:  [d b a c e]
N:5 Out:[f d b a c e]
N:6 Out:[f d b a c e g]
```
The output should be `[f d b a c e g]`.
# Another example
```
The input is [u d l n u e m p].
N:0 Out:        [u]
N:1 Out:      [d u]
N:2 Out:      [d u l]
N:3 Out:    [n d u l]
N:4 Out:    [n d u l u]
N:5 Out:  [e n d u l u]
N:6 Out:  [e n d u l u m]
N:7 Out:[p e n d u l u m]
```
## Test cases
[Here](https://tio.run/##lVLNaoQwEL77FHNZMBhl22OXLeToZdmjyxJK6o5LQKONkV767naibbQUSp1LyMz3MzMJ2lqZe4p9aXXnxjHq0NyGemjiq@QgOLwwSJ9BHKJV5fJRzMXcFyOg2IFun96tdhgLxpeUqeOvq66mw0cOFht4hOMR9l59B6Lz6llA@Ah@BXlBksD1Qq45JPDADgHp7ICzxtni3yLE9zLiW2QCToxltiJMtGLSKvaMUI3ShvYSIGHkZTWKv/KS3zjyit8lY/znDn4T5Lpb@AdBya2EuSW5hSA3OyjyIB@5JmT0KqfWpIPRb/RKDnuXlqpHqGzb0B@gZO@ycfwE)'s a sample program doing this encoding.
Take note that the characters in the string aren't always unique.
```
Your output *has* to be flattened.
[a,b,c,d,e,f,g]   -> [f,d,b,a,c,e,g]
[]                -> []
[a]               -> [a]
[a,b,c,d]         -> [d,b,a,c]
[a,b]             -> [b,a]
[a,b,d]           -> [b,a,d]
[a,b,a,c,b,c]     -> [c,c,b,a,a,b]
[a,a,b,b,c,c]     -> [c,b,a,a,b,c]
[u,d,l,n,u,e,m,p] -> [p,e,n,d,u,l,u,m]
```
  
[Answer]
# [Python 3](https://docs.python.org/3/), 29 bytes
```
lambda l:l[1::2][::-1]+l[::2]
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHHKifa0MrKKDbaykrXMFY7JxrE@V9QlJlXopGmoVSakpNXmppboKSpyQUXTExKTklNS8ciBhT6DwA "Python 3 – Try It Online")
**Input**: A sequence  
**Output**: The pendulum encoding of that sequence
**How**  
Consider the sequence `[0,1,2,3,4,5]`, whose pendulum encoding is `[5,3,1,0,2,4]`. We can see that all even indices ended up in order on the right, and all odd indices are in reversed order on the left.
* `l[1::2][::-1]` takes all odd indices and reverses them, e.g `[5,3,1]`
* `l[::2]` takes all even indices, e.g `[0,2,4]`
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), ~~24 21~~ 18 bytes
```
,[[<],[>],<]>>[.>]
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fJzraJlYn2i5WxybWzi5azy72///SlJy80tTcAgA "brainfuck – Try It Online")
Thanks to Jo King for -3 bytes
```
,[          while input
  [<],      add new character to start of memory
  [>],      add new character to end of memory
  <         go one back, so the loop will run another time, moving the pointer to the start of memory
]
>>[.>]      print memory
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 11 bytes
I promised you'll see at least one interesting answer :)
```
{⍵[⍋-\⍳≢⍵]}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pR79boR73dujGPejc/6lwE5MbW/k971DbhUW/fo76pnv6PupoPrTd@1DYRyAsOcgaSIR6ewf/TFNQTk5JTUtPS1bmA7NKUnLzS1NwCdQA "APL (Dyalog Unicode) – Try It Online")
Uses [my own tip about `-\⍳`](https://codegolf.stackexchange.com/a/200637/78410), specifically the `⍋` variation, to generate the permutation needed for this challenge.
### How it works
`⍋-\⍳≢⍵` generates the target permutation for both even- and odd-length arrays:
```
⍋-\⍳≢⍵  ⍝ Length-7 vector  | Length-8 vector
    ≢   ⍝ Length
        ⍝ 7                | 8
   ⍳    ⍝ Range (1..n)
        ⍝ 1 2 3 4 5 6 7    | 1 2 3 4 5 6 7 8
 -\     ⍝ Cumulative alternating difference
        ⍝ 1 -1 2 -2 3 -3 4 | 1 -1 2 -2 3 -3 4 -4
⍋       ⍝ Grade up; permutation that will sort the input array
        ⍝ 6 4 2 1 3 5 7    | 8 6 4 2 1 3 5 7
```
Then `⍵[...]` arranges the original elements in that particular order.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ι`Rì
```
I/O as a list of characters.
[Try it online](https://tio.run/##yy9OTMpM/f//3M6EoMNr/v@PVipV0lFKAeIcIM4DYhA/FYhzgbhAKRYA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXR/3M7E4IOr/mv8z9aKTEpOSU1LV1JRwmIEkEYKACmwASEmZiclAxiJCYlJYMYpSk5eaWpuQVKsQA).
**Explanation:**
```
ι     # Uninterleave the (implicit) input-list (into 2 parts by default for lists)
      #  i.e. ["u","d","l","n","u","e","m","p"] → [["u","l","u","m"],["d","n","e","p"]]
 `    # Push both parts separated to the stack
  R   # Reverse the second part
      #  → ["p","e","n","d"]
   ì  # And prepend it in front of the first
      #  → ["p","e","n","d","u","l","u","m"]
      # (after which the result is output implicitly)
```
[Answer]
# JavaScript, 36 bytes
Feels like forever since I posted a JS solution here!
Input as an array, output as a string. Handling the empty array cost 3 bytes.
```
a=>a.reduce((x,y,z)=>z%2?y+x:x+y,"")
```
[Try it online!](https://tio.run/##XckxCoAgFADQvWMIgaL9oTHQDhINor8oTKMytMtbc@t7q771aY5lvxofLJZJFi2VhgNtNEhpElk8TKqnbvvMU5d4FoSwYoI/g0NwYaYTHQCAROt8xG0nI2PV7z8qLw)
[Answer]
# [Haskell](https://www.haskell.org/), ~~53~~ 37 bytes
```
([]#)
p#(a:b:s)=(b:p++[a])#s
p#l=p++l
```
[Try it online!](https://tio.run/##PYhBDoMgEEX3nmICLiC2FyDhJMhiQLHG0Uyk5@@oiXbz3vv/g3UZiaT4XkyI2jasDbrkqvUmOe66gNHqet7kz0Wy4ryBB97n7QstrMhQIChMWb0uDrfGx@Ufk4ryy4VwqvLOzAc "Haskell – Try It Online")
*Golfed 16 bytes thanks to @xnor*
[Answer]
# JavaScript (ES6), 42 bytes
A recursive function taking and returning a string.
```
f=([c,...a],k,o='')=>c?f(a,!k,k?c+o:o+c):o
```
[Try it online!](https://tio.run/##bc5BDoIwEIXhvaeoqymhlj0JchDjYjptiVI6RMTrI0SiIMz6y//mji/s6HFrn6fI1g2DL@SFlNYar6pWXAAkxZlKL1Eda1WXlHLOKSU5D8Sx4@B04Ep6CWjIOl@BSBKRZQK8NUiugsOfAzHf7DYAYQ1wK8YpWIhpaQfBKmP2Op/Mj9gdg2QIvobI4JjeMDSGlmxS26d6G2LvmhZm1rpo@9A3MLwB "JavaScript (Node.js) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~6~~ 5 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 thanks to [Unrelated String](https://codegolf.stackexchange.com/users/85334/unrelated-string)! (Use an initial value for reduction.)
```
;ṭƭƒ“
```
**[Try it online!](https://tio.run/##y0rNyan8/9/64c61x9Yem/SoYc7////VS1Ny8kpTcwvUAQ "Jelly – Try It Online")**
A full program that accepts a string and prints the result.
### How?
```
;ṭƭƒ“ - Main Link: list of characters, S
    “ - get an empty list -> X
   ƒ  - reduce (X + S) using:
  ƭ   -   tie - this groups the last n (default 2) links together and calls them cyclically:
;     -     concatenate  (i.e. on the first, third, fifth,... we append)
 ṭ    -     tack         (     while on the second, fourth,... we prepend)
      - implicit, smashing print to STDOUT
```
It could be considered a bug that Jelly barfs if the non-initialised version of reduce, `/`, is provided with an empty list. If that were 'fixed' this becomes just the four-byte `ṭ;ƭ/`.
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg), `-lp`, `-ir`, `-hd`, 15 bytes
```
⑫&(&⑶+&)⒁2%[⒂|&
```
[Try it online!](https://tio.run/##y05N////0cTVahpqjyZu01bTfDSp0Ug1@tGkphq1//9LU3LySlNzC/7r5gBxZtF/3YwUAA "Keg – Try It Online")
Purely a literal interpretation of the question plus a bit to ensure even length strings don't break.
## Explained
```
⑫&
```
First, we start by storing an empty string (pushed by `⑫`) in the register. This will be used as the final output, meaning that it needs to be initalised.
```
(&⑶+&)
```
Then, we enter the main for loop, which has the implicit condition `!` (take length of stack), as no explicit condition is provided. Now, there isn't anything on the stack at this point, so doing such a thing may seem pointless. But, by using the `-lp` flag (`--lengthpops`), we can have the `!` command take input if the stack is empty and push the length of the input. Also, the `-ir` (`--inputraw`) command ensures that the input word is taken as a series of letters, rather than a single string.
Inside the for loop, we push the contents of the register, reverse it (`⑶` reverses the top item of the stack) and then add whatever is next to the register. By doing so, we achieve the process behind the main algorithm, as consecutive letters are appended in the desired order.
```
⒁2%
```
At this point, the encoding has been fully completed. However, if the string is of an even length, the result will be reversed in the register. This requires us to push the length of the register (`⒁`) and check to see if it is even.
```
[⒂|&
```
If the register is of odd length, then we reverse the register and push it onto the stack (`⒂`). Otherwise, we simply push the register. `-hd` will then ensure that only the top item on the stack is printed.
[Answer]
# [Red](http://www.red-lang.org), 52 bytes
```
func[a][append reverse extract next a 2 extract a 2]
```
[Try it online!](https://tio.run/##PcgxDoAgDAXQnVM0HMHRY7gShko/xkQbUsF4e2Rie3kG6RskRJfXnpumwDFwKVAhwwt7QPiqcaqkA8S0zBiOvdiplTJ53pMgH97NaXJpw118/wE "Red – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 13 bytes
```
{~[:/:[:-/\#\
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/q@uirfStoq109WOUY/5rcilwpSZn5CukKagnJiWnpKalq8MFSlNy8kpTcwvgIoYKRgrGCiYKpgpm/wE "J – Try It Online")
A [J](http://jsoftware.com/) port of [Bubbler's APL solution](https://codegolf.stackexchange.com/a/201563/75681) - don't forget to upvote his answer!
```
           #\  length of successive prefixes
        -/\    cumulative alternating difference
      [:       function composition (caps the previous two verbs as a fork)
    /:         grade up 
  [:           caps the fork
{~             use the list to index into the input (arguments reversed)
```
[Answer]
# [Perl 5](https://www.perl.org/) `+p`, 30 bytes
```
$\=--$|%2?$\.$_:$_.$\for/./g}{
```
[Try it online!](https://tio.run/##K0gtyjH9X5xYqaESo6mjUmNroKMSY6uunpmmEmP9H8jU1VWpUTWyV4nRU4m3UonXU4lJyy/S19NPr63@/z8xKTklNS2dqzQlJ680NbfgX35BSWZ@XvF/3YL/ur6megaGAA "Perl 5 – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `r`, 3 bytes
```
yṘJ
```
Uninterleave, reverse the second argument, merge b + a. Requires the r flag because there's no way to merge to my knowledge the other way around in one command.
[Try it Online!](https://lyxal.pythonanywhere.com?flags=r&code=y%E1%B9%98J&inputs=%5B%22a%22%2C%22b%22%2C%22c%22%2C%22d%22%2C%22e%22%2C%22f%22%2C%22g%22%5D&header=&footer=)
And flagless from @AaronMiller if the input is taken as a string:
## [Vyxal](https://github.com/Vyxal/Vyxal), 3 bytes
```
yṘp
```
Instead of J to merge, it prepends the element.
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=y%E1%B9%98p&inputs=udlnuemp&header=&footer=)
[Answer]
# [Zsh](https://www.zsh.org/), 26 bytes
```
for x y;a=($y $a $x)
<<<$a
```
[Try it online!](https://tio.run/##Lcq5DYAwDAXQPlO4sOR4BsIw5jAUXAIhJSxvHEHxin8812waOZruJ2QojbQRC6AAZg4pJRTjEBRICKhzvRvc6NRNVNf7bxe30ZfrY3UH2Qs "Zsh – Try It Online")
Input is a list of characters.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 20 bytes
```
*>^`.(.)?
$1
1,2,`.
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8F/LLi5BT0NP055LxZDLUMdIJ0GP679eDFAmMSk5JTUtnas0JSevNDW3AAA "Retina – Try It Online") Link includes test suite. Explanation:
```
*>`
```
Execute this stage and immediately output the result without actually changing the working string.
```
^`
```
Before making the replacements, reverse their order.
```
.(.)?
$1
```
Keep only alternate characters.
```
1,2,`.
```
Delete alternate characters.
29 bytes as a reusable function:
```
,V,2,`
O^$`.((?=(..)*$))?
$#1
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8F8nTMdIJ4HLP04lQU9Dw95WQ09PU0tFU9OeS0XZ8P//xKTklNS0dK7SlJy80tTcAgA "Retina – Try It Online") Link includes test cases. Explanation:
```
,V,2,`
```
Reverse all the characters except alternate characters.
```
O^$`.((?=(..)*$))?
$#1
```
Sort all characters by the parity of their position from the end, and then reverse the result. This means that alternate characters end up reversed and sorted to the start, leaving the remaining characters at the end, although technically having been reversed twice.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes
```
Ｆ²«Ｐ✂θιＬθ²←↷⁴
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBw0hToZqL07c0pySzoCgzr0QjOCczOVWjUEchU0fBJzUvvSRDo1BTR8FIU9MaqC6/LFXDyic1rQTEC8gsyy8JykzPKNEwAfJr//8vTcnJK03NLfivW5YDAA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｆ²«
```
Loop over the even and alternate characters.
```
Ｐ✂θιＬθ²
```
Print the current set of characters.
```
←↷⁴
```
Prepare to print the alternate characters backwards.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 42 bytes
```
f=->s,*w{s ?f[s[2..-1],s[1],*w,s[0]]:w*''}
```
[Try it online!](https://tio.run/##KypNqvz/P81W165YR6u8uljBPi26ONpIT0/XMFanOBpIaJUDaYPYWKtyLXX12v8FpSXFCmnRSqUpOXmlqbkFSrFcMKHEpOSU1LR0DBGl2P8A "Ruby – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 60 bytes
```
a->{var r="";for(var c:a)r=r.length()%2<1?r+c:c+r;return r;}
```
[Try it online!](https://tio.run/##VU5Nb4MwDL3zKywkJFhptO4IpdM0abedeux6MIHQMAjISZBQxW/PAu1lkr@e7efnFifct9Wvk/04kIHWY2aN7Jiwihs5KPaSB6MtO8mBd6g1fKNUcA8Anl1t0Pg0DbKC3s/isyGpmssVkBqdbKsAX89zR35DulzTx9IJROFwf7pPSEBFGOZioHgFPMOECmJdrRpzi5Po7Xh4px3P@I5yqo0lBZQvLt@uexZsNC@Z/dMFOM/a1D0brGGj1zQiDqPDq87gJ4y0dxWmKyMFwXAcuzn2gJnh0//5QYRznCTJQ2UJVl@cw5JXtWh8sZU@eFsT8pI7xLLk3NmqU7buxz8 "Java (JDK) – Try It Online")
## Alternative with Streams (62 bytes)
```
s->{int[]x={0};return s.reduce("",(a,b)->x[0]++%2<1?a+b:b+a);}
```
[Try it online!](https://tio.run/##bVBNb4MwDL33V1hISGHQqN2xtEy77LZTj10PTggoHYQoH1Writ@eBcpl2iLbz/Gz86xc8IrrS/0dZK8H4@AS79Q72dGXcvWn1njFnRzUv6R1RmA/UdqzTnLgHVoLnygVPFYAS9U6dBGug6yhjxw5OiNVezoDmtZmcyvAx6K0P86v7p9NVbEgNIdg19VDKnc63w6PzVga4bxRYKkRteeCJElBsGDZurqdNuc8T1/32zfM2Y7lmJVjKGedZjBArmgm8d2vDQCOd@tETwfvqI6qriFJut3YHXwlqY2ukmKaKKChqHV3J@/G4N0uH0EiRa3upIurZPE8BcfV5GMIyHgtmjYmcxpDtAmQMx4QGeM8@LpTXvT6Bw "Java (JDK) – Try It Online")
[Answer]
# [PHP](https://php.net/), ~~49~~ 48 bytes
```
for(;$a=$argv[++$i];)$s=$i%2?$s.$a:$a.$s;echo$s;
```
[Try it online!](https://tio.run/##DcVBCoAgFAXAy7ygEFy0zMSDRItPWQqVotT1X25mcsicXW4eqfQGYiHl/BalEFczoFrEbnSoGjJBNKrxW0gtki93XnzanjfzDw "PHP – Try It Online")
Again, not a really great score for PHP..
EDIT: Thanks for @OlivierGrégoire for saving 1 byte
[Answer]
# [Icon](https://github.com/gtownsend/icon), 62 bytes
```
procedure f(s)
t:=""
t[k:=|(0|1)\*s:k]:=pop(s)&\z
return t
end
```
[Try it online!](https://tio.run/##Xc2xCsMgEMbx3aeQG4qWDu0q@CRJhlTPImlULkqg5N3Ta8lQOvym@39cdDnte6Hs0DdCGdSiRTUWQNRuMnZT1@2m@/NipsHYkgvfT/1LENZGSVaByf/M5zEmpYWUcqVYUQXVwQgXuDPHPEMW2AMG/Ze2I3myxNqRz6x888@7Nw "Icon – Try It Online")
Takes the input as a list of chars. 
# [Icon](https://github.com/gtownsend/icon), 66 bytes
```
procedure f(s)
t:=""
i:=1to*s&t[1-i%2:1-i%2]:=s[i]&\z
return t
end
```
[Try it online!](https://tio.run/##VcyxCsIwEIDhPU9xBCyJ4FDHQJ6kdqjJRQ7spVwuCL58pU66/MM3/JQq7/smNWHuglBc80ZDtNZQiKPWcxt0Gi90uoZv5xDbRPNwextB7cKgBjn/LNaF2HkDAC8hRVecXe4pY3lY/889P7njuh1@PD4 "Icon – Try It Online")
Takes the input as a string.
`procedure`, `return` and `end` add a lot to the byte count :)
[Icon](https://github.com/gtownsend/icon)'s `slice` operator `:` can be used to insert substrings into strings, if the the two indices are equal. This `s[1:1]:="a"` prepends `s` with "a"; `s[0:0]:="b"` appends "b" to `s`. I start with an empty string `t`, scan the input string `s` and use the odd/even index `i` with the slice operator to prepend/append to `t`.
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 93 bytes
```
public static string P(this string a){int z=0;return a.Aggregate("",(x,y)=>z++%2>0?y+x:x+y);}
```
[Try it online!](https://tio.run/##VY3BasMwEETv@goRKEg4NabHiqSEXFsw5JBDyEF1FlVgS@nuqtgJ/nbVqVto5rIMvHnb0GMTEXIiH5zcDcTQGfG/la8@fBohzum99Y0ktjydprVEssbo0HbiKuQt98hX9Cf5Zn1QxDj5Dkdp0ZGe2d/JT7YxUGyh3KNnmN6BuoGH6ljWSmszk2O@189SWSv@8PTXrL76wPKyqgwCJwzSlhvnEJxlUIvFUvXLQa/Wl6J4eFpXL0PRP/fFoM2Yx5zTqQ0JuvM3 "C# (.NET Core) – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-P`](https://codegolf.meta.stackexchange.com/a/14339/), ~~7~~ ~~6~~ 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
I/O as a string.
```
ó ÔvÔ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVA&code=8yDUdtQ&input=InVkbG51ZW1wIg)
```
ó ÔvÔ     :Implicit input of string    > "udlnuemp"
ó         :Uninterleave                > ["ulum","dnep"]
  Ô       :Reverse                     > ["dnep","ulum"]
   vÔ     :Reverse first element       > ["pend","ulum"]
          :Implicitly join and output  > "pendulum"
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 10 bytes
```
ORVDQUW:aa
```
[Try it online!](https://tio.run/##K8gs@P/fPyjMJTA03Cox8f///6UpOXmlqbkFAA "Pip – Try It Online")
-4 from DLosc.
## Similar solution, 14 bytes
```
UW:a(RVa@1).@a
```
[Try it online!](https://tio.run/##K8gs@P8/NNwqUSMoLNHBUFPPIfH///@lKTl5pam5Bf91CwA "Pip – Try It Online")
[Answer]
# Scala, 51 bytes
```
_./:(0,""){case(i->a,c)=>i+1->Seq(a+c,c+a)(i%2)}._2
```
[Try it online](https://scastie.scala-lang.org/PI3QQdwmQwC2ZuxLscF48Q)
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 26 bytes
```
s/(.)(.)/$\="$2$\$1";''/ge
```
[Try it online!](https://tio.run/##K0gtyjH9/79YX0NPE4j0VWJslVSMVGJUDJWs1dX101P//y9NyckrTc0t@JdfUJKZn1f8X7fgv66vqZ6BoQEA "Perl 5 – Try It Online")
[Answer]
# [Factor](https://factorcode.org/), 47 bytes
```
[ dup <odds> ""reverse-as swap <evens> append ]
```
[Try it online!](https://tio.run/##RY67DsIwDEX3fIWVnX4AIFbEwoKYEIOTuAi1TYOd8BDi20MkaOPF99wz2C3aOHI@Hnb77RI6Yk89CN0SeUtSU0PPyCgQmGJ8Bb76CCul3grKaDTWUXvRP/ov1FXOcQ61QmvsBGiMnSC53icaglaffAKXAqxH52RTDjDdiYUW5SF5YBGFfTEYAnkH5zyUUiLarslf "Factor – Try It Online")
## Explanation
It's a quotation (anonymous function) that takes a string from the data stack as input and leaves a string on the data stack as output. Assuming `"udlnuemp"` is on top of the data stack when this quotation is called...
* `dup` Duplicate whatever's on top of the stack.
**Stack:** `"udlnuemp" "udlnuemp"`
* `<odds>` Get the odd-indexed elements as a virtual sequence.
**Stack:** `"udlnuemp" T{ odds f "udlnuemp" }`
* `""` Push an empty string to the stack.
**Stack:** `"udlnuemp" T{ odds f "udlnuemp" } ""`
* `reverse-as` Take a source sequence and an exemplar sequence, and create a new sequence where the source sequence is reversed, but with the type of the exemplar sequence.
**Stack:** `"udlnuemp" "pend"`
* `swap` Swap the top two objects on the data stack.
**Stack:** `"pend" "udlnuemp"`
* `<evens>` Get the even-indexed elements as a virtual sequence.
**Stack:** `"pend" T{ evens f "udlnuemp" }`
* `append` Append two sequences. The result of `append` has the same type as the first argument.
**Stack:** `"pendulum"`
[Answer]
# [Rockstar](https://codewithrockstar.com/), ~~135~~ ~~125~~ ~~115~~ 96 bytes
```
listen to S
cut S
X's 0
O's ""
while S
let X be not X
let O be X and O+roll S or roll S+O
say O
```
[Try it here](https://codewithrockstar.com/online) (Code will need to be pasted in)
[Answer]
# [minigolf](https://github.com/jfioasd/minigolf/), 36 bytes
```
0,;i,unx2%!,,__a,n_nx2%,,__xo,;o_s,_
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iNzMvMz0_J23BgqWlJWm6FjdVDHSsM3VK8yqMVBV1dOLjE3Xy4kEcELsiX8c6P75YJx6iFqplwcpoAx1DHSMd41iIAAA)
## Explanation
```
0,;        Start with an empty list
i,         Foreach item in input:
  u            Store list to acc
  n            Push curr. item
  x2%!,        If iteration index is even:
    ,_             drop TOS
  _            end
  a            Push acc
  ,n_          Dump acc onto stack
  n            Push curr. item
  x2%,         If iteration index is odd:
    ,_             drop TOS
  _            end
  xo           Iteration index + 1
  ,;o          Wrap last n items of stack into array
_            End foreach
s,_          (For some reason we have an extra implicit input,
              so swap it upwards and drop it)
```
[Answer]
# [Python 2](https://docs.python.org/2/), 25 bytes
```
lambda s:s[-1::-2]+s[::2]
```
[Try it online!](https://tio.run/##K6gsycjPM/r/PycxNyklUaHYqjha19DKStcoVrs42srKKPb/fwA "Python 2 – Try It Online")
Wrote this before I took a look at the submissions. The Python 3 answer is basically the same, but I improved the slicing to reverse the odd indices all in one.
But yeah, you can construct the pendulum encoding in two parts. First, the odd indices in reverse order. Second, the even indices in normal order.
[Answer]
# [Lua](https://www.lua.org/), 56 bytes
```
s=''(...):gsub('(.)(.?)',load'a,b=...s=b..s..a')print(s)
```
[Try it online!](https://tio.run/##DclhCoAwCEDh46gwPEAgnUVZRLDWyDy/@efxwRuhmS4AyMy0nR6GZULeCdp4tIM2k5ouVmFWoPVe80OnzIw@Zhz3@gE "Lua – Try It Online")
]