# Pendulum Encoding

## Python 3, 29 bytes

lambda l:l[1::2][::-1]+l[::2]


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]

## brainfuck, 24 21 18 bytes

,[[<],[>],<]>>[.>]


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


## APL (Dyalog Unicode), 11 bytes

I promised you'll see at least one interesting answer :)

{⍵[⍋-\⍳≢⍵]}


Try it online!

Uses my own tip about -\⍳, 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.