# [GNU sed], 261 + 1 = 262 bytes +1 byte for `-r` flag. s/000/;/g s/111/_/g s/0//g s/$/;:51111141111_3111__211___i1____6_11117__1118___119____10_____H1111V111_F11_1L1_11P1__1J1___B_111X_11_C_1_1Y_1__Z__11Q__1_S111U11_R1_1W1__D_11K_1_N__1G__1O___I11A1_M__E1T_/ : s/([1_]+);(.*([^1_])\1)/\3\2/ t y/i/1/ s/;/ /g s/:.*//g [Try it online!][TIO-ja46wzt0] [GNU sed]: https://www.gnu.org/software/sed/ [TIO-ja46wzt0]: https://tio.run/##bU/JUoNQELzzFR48QKxkphNXOLnvcV@DzkXL4mIsycWfF3sgIag8qnuWZvq9yV9fiiIXVZVE3oJcAIiVmUoZFiWJV@Bn2ckGTtZ3sszJVs2FNfOwbh42vA11tgMXb31oj8AJgXPO4ciHt3zonmTbRuWBZI9ucUGyK4o31C4p3VHZoXDM/pDiPnFGh0NgE3ZqtotrkyDmk8MR7GkpSsJeJxw9M49SRJIO0r4Ek@BLMoHwt0QWyg3jXoerFgW0@nQKXl7XjRyoUZ1m/VudzbU4KIKqmjtoq2@dN71mnTpWbn9uB/5BtbWH@fumTm27KL7HH5Ns/J4X3c8f "sed 4.2.2 – Try It Online" ## Explanation This is a very basic lookup table solution. The first three lines transform the input so dashes are `_`s and dots are `1`s. First, `000`s are replaced with `;`, so characters are separated by `;` and words by `;;0`. Then `111`s are replaced by `_` and all remaining `0`s are discarded, leaving `1`s for dots. s/000/;/g s/111/_/g s/0//g The next line appends the lookup table. It takes the form `cmcmcm...` where `c` is a character and `m` is the sequence of `_`s and `1`s representing it. `i` is substituted for `1` in the table for disambiguation. Since regular expressions in sed are always greedy, the table is sorted from longest to shortest code (so e.g. `1_` matches `A1_` instead of `i1____`). s/$/;:51111141111_3111__211___i1____6_11117__1118___119____10_____H1111V111_F11_1L1_11P1__1J1___B_111X_11_C_1_1Y_1__Z__11Q__1_S111U11_R1_1W1__D_11K_1_N__1G__1O___I11A1_M__E1T_/ Next, in a loop, each sequence of `_`s and `1`s (and the subsequent `;`) is replaced by the corresponding character: : s/([1_]+);(.*([^1_])\1)/\3\2/ t Finally, cleanup: `i`s are replaced with `1`s, remaining `;`s are spaces, and the lookup table is deleted: y/i/1/ s/;/ /g s/:.*//g