APL(Dyalog Unicode), 3333 26 bytes SBCS
A port of Nick Kennedy's Jelly answer.
4(' -' '1ijk'⌷⍨¨⌊⍤÷⍨,|)8|⊢⊥⍨3*2|⊢'1ijk'⌷⍨¨2 4⊤⊢⊥⍨3*2|⊢
Try it on APLgolf!Try it on APLgolf!
A train submission which takes a list of codepoints as the right argument.
APL has mixed radix decode (⊥
) which makes the calculation part quite short:
2|⊢ ⍝ each value in the input modulo 2
3* ⍝ raise 3 to this power
⊢⊥⍨ ⍝ use the resulting numbers as a mixed radix to decode the input
8| ⍝ modulo 8
Technically the 2|
is not needed, but without it even the test cases with 2 characters start to fail because of very large numbers.
⌊⍤÷⍨,|2 4⊤
is divmod with swapped argumentscalculates 4|⊢
and 2|4÷⍨⊢
, and both resulting integers are used to index into one string.