Jelly, 15 13 bytes (thanks @Jonathan Allan!)
OH+53œ?@ƒ5FṢƑ
OH+53œ?@ƒ5FṢƑ
O ƒ Reduceord() the input list with:(vectorizes)
O H Divide by 2 ord(vectorizes)
H + Divide by 2Add...
+ 53 ...53 (all these steps Add...vectorize)
53 ƒ Reduce the input ...53list with:
@ The preceding dyadic link, with its arguments swapped:
œ? The nth permutation of the right argument
...using the following as the starting value for the reduce:
5 5 (which gets implicitly converted to [1,2,3,4,5] by œ?)
F Flatten (implicitly wraps 5 into [5] in case the input list is empty)
Ƒ Check if the output of the previous link is equal to its left argument:
Ṣ Sort the output list
(The last two bytes effectively check if the list is already in sorted order.)
Uses essentially the same logic as @xnor's answer. The two permutations I used were 45231
and 45123
, since their indices (94 and 91, respectively) can be easily computed from the ord
values of 'R' and 'L' (82 and 76, respectively): divide by 2 and add 53. I wrote a Python script to check all valid pairs of permutations to find the optimal ones (in terms of how many bytes are needed to calculate their indices from 82 and 76), and no other permutations were better than these.