Unique characters: Difference between revisions

Add ed example
(Added Easylang)
(Add ed example)
Line 737:
156bgstz
</pre>
 
=={{header|ed}}==
 
<syntaxhighlight lang="sed">
H
g/.*/s/$/|/
,j
# Remove duplicate chars, across the string boundary
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
s/([^|])([^|]*)\|(.*)\1/\2|\3/g
# Remove duplicate chars, inside strings
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/([^|])([^|]*)\1/\2/g
s/\|/\
/g
d
,p
Q
</syntaxhighlight>
 
{{out}}
 
<pre>$ cat unique-chars.ed | ed -lEGs unique-chars.input
15bfd
6st
cgz</pre>
 
Notice the "c" in the last part—due to the algorithm first deduplicating things across strings, some chars are left over in individual strings. Still, the algo is pretty good overall. No alphabetical sorting either—to save space.
 
=={{header|Factor}}==
100

edits