# Append and erase

Given one line that consists of only letters, process as following:

• You maintain a string that's empty at the beginning.
• If the next input character is in the string, remove it from the string.
• If the next input character isn't in the string, append it to the string.

Output the final state of the string.

You can safely assume the input consists at least one character (i.e. non-empty), but there's no guarantee that the output isn't empty.

Pseudocode (Feel free to golf this):

str = EMPTY
for each character ch in input
if ch exists in str
remove all ch from str
else
append ch to str
print str


The input matches the regular expression ^[A-Za-z]+\$.

Sample test cases:

ABCDBCCBE -> ADCBE
ABCXYZCABXAYZ -> A
aAABBbAbbB -> aAbB
GG -> (empty)


The input can be given in any applicable way, but it must be treated as a string, and the same for output. The program should not exit with an error.

The shortest program in each language wins!

• May the line be empty? – user202729 Nov 28 '17 at 15:37
• @user202729 No. I changed a little (it does not invalidate any answer) so the input is never empty. – iBug Nov 28 '17 at 16:03
• So why did you reject ais523's edit suggestion (link)? – user202729 Nov 28 '17 at 16:09

# Julia 0.6, 49 bytes

~x=foldl((s,c)->in(c,s)?replace(s,c,""):s*c,"",x)


Try it online!

Algorithm from the pseudocode. This does not work like this in tio.run because concatenation of a string with a char using * is not defined. It does work in JuliaPro 0.6.1.1 however, where this is defined from the future™ (0.7 dev).

# Japt-h, 15 bytes

;£A=øX ?AkX:ApX


Try it online!