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
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. CharactersFirst, 000
s are replaced with ;
, so characters are separated by ;
and words by ;;0
. Then 111
s are separatedreplaced 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