# [Jelly], (26?) 27 [bytes] <sup>26 if the result need not be flat (while still consistent) - remove trailing `F`</sup> iⱮ’“¡©“®¢‘xⱮj€12b4;,a"4,1ɗF A dyadic Link that accepts the starting data stack in reverse on the left and the final data stack in reverse on the left and yields a list of integers: 0 >r 1 r> 2 swap 3 dup 4 drop **[Try it online!][TIO-ksni1qlx]** (Footer formats like the question does.) Or see the [Python suite of test results][1]. ### How? This builds the reverse of the final data stack in the return stack one item at a time by "copying" the item from the data stack, leaving the data stack unaffected, then it drops all of the original items from the data stack and pulls all the copied items back. To "copy" an item it pushes all those above it, then repeatedly pulls and swaps so that all the original main items are back on the data stack with the required item on top, then duplicates and pushes and then performs the conjugate of everything before the duplication to get main back to how it started. For example, to push `d` from `abcd...` (where `a` is on top): >r >r >r r> swap r> swap r> swap dup >r swap >r swap >r swap >r r> r> r> ...or (>r)*3 (swap r>)*3 (dup >r) (swap >r)*3 (>r)*3 Where `3` is three because there are three items on top of `d`. ##### Code breakdown iⱮ’“¡©“®¢‘xⱮj€12b4;,a"4,1ɗF - Link: starting (reversed); final (reversed) Ɱ - map with: i - first index of (final item) in (starting items) ’ - decrement -> 0-based indices “¡©“®¢‘ - code-page indices = [[0,6],[8,1]] Ɱ - map with: x - times - e.g. 3 -> [[0,0,0,6,6,6],[8,8,8,1,1,1]] j€12 - join each with twelves b4 - convert from base four 0->[0]; 6->[1,2]; 12->[3,0]; 8->[2,0]; 1->[1] ɗ - last three links as a dyad - f(starting, final): , - pair -> [starting, final] e.g. ["abc","ba"] 4,1 - [4,1] [4,1] " - zip with: a - logical AND [[4,4,4],[1,1]] ; - concatenate F - flatten [Jelly]: https://github.com/DennisMitchell/jelly [bytes]: https://github.com/DennisMitchell/jelly/wiki/Code-page [TIO-ksni1qlx]: https://tio.run/##y0rNyan8/z/z0cZ1jxpmPmqYc2jhoZUgat2hRY8aZlQAxbMeNa0xNEoysdZJVDLRMTw53e3/4eUPd3cDVRXZAYni8sQCIJVSCiaL8kGUXdGjhrne//@nJCcl/k9MSk4BAA "Jelly – Try It Online" [1]: https://tio.run/##vVRNj9MwEL37Vww5pVJSCbhVaiUOCwcOe1m4VD24zoS1NtiW46i7Qvz2Mv5I0naTwsKKKKo/5703byY1T@5eq/fHY4U14COKzmHeOi4eChC6wsWKAT1hB9Zx3K52YdP2u9u4rrWFg7YVSBVil61ppMsThH9kHS@s15BVVptsPBpYlkabfDHsY3MW1E3HcGNQVVH4tny7m4tvD3wSwMcU/fTdbsiU5sV4YwZ0Yy8g7XNRMas5WXZzLSs7g9DiBS2XLcJX3nR4Y622eZ19UQ9KH1RgWsEPP/zMIgZvW7RuKKKvYpFWsbroOquiEsZ8ezhsneAt5ljXKNxZg@yRqo8F8NqhJfu@c0OJ29gCBcSI1BBZWWYpEWefxhx05yiyb8IeMZCEO/go0LjxvrFSEdodyYKaywarVdZTjT4FV1jqPk/xZh1VvhQo3fqknT8lpAsO@BAclVoF96Nn39A1UmH/Efg55SiV6Vxq8sM9EYaDJRkmqcahJU4aYiIoFcefMDaYGKHubHfSGDELCh@UDEfe2cmD6UKz6D/c3H4MCUYOQ33EWPLm9nO2OB457KEswQ@cbSzYDfjvDujjBVqGedxOO9fv0P9E/KFFeBlLDHvPwf4IJO5MYQn4d7QJecJDit6CE7gZ2BN4el@H3g9/Rf@yukzSV15ARZaK6y0QaSYE/kboueBZV65pO63OKwj4P2U@S4jeXw "Python 3 – Try It Online"