Let's do some location arithmetic!
JavaScript (ES6), 136 134 133 bytes
Saved 1 byte thanks to Luke
s=>[...a='abcdefghijklmnopqrstuvwxyz'].filter((c,i)=>eval(s.replace(/\w+/g,s=>[...s].reduce((p,c)=>p|1<<a.search(c),0)))&1<<i).join``
Test cases
let f =
s=>[...a='abcdefghijklmnopqrstuvwxyz'].filter((c,i)=>eval(s.replace(/\w+/g,s=>[...s].reduce((p,c)=>p|1<<a.search(c),0)))&1<<i).join``
console.log(f('ab + bd')); // acd
console.log(f('d - ab')); // ac
console.log(f('ab * cd')); // cf
Mathematica, 168 bytes
FixedPoint[StringReplace[x_~~x_:>FromCharacterCode[c@x+1]],Table["a",ToExpression@StringReplace[#,x:LetterCharacter..:>ToString@Tr[2^((c=ToCharacterCode)@x-97)]]]<>""]&
My initial solution (before the post was edited to clarify that the output must be simplified) was 64
bytes shorter:
Table["a",ToExpression@StringReplace[#,x:LetterCharacter..:>ToString@Tr[2^(ToCharacterCode@x-97)]]]<>""
This just modified that solution to work. It's probably shorter to actually use the methods described in the challenge, but I wanted to put this up anyway.
Explanation:
Replaces each sequence of letters with its corresponding integer by character code arithmetic, then converts the resulting string to an expression (which will automatically simplify to an integer), then produces a string of a
characters of length equal to that integer, and finally replaces adjacent identical characters with the next character code up until a fixed point is reached.
Perl 5, 95 bytes
94 bytes of code + -p
flag.
s/\w/a x 2**(-97+ord$&)/ge;s/(.*)-\1|\+//;/\*/&&($_=$`x length$');1while s/(.)\1/chr 1+ord$1/e
Try it online!
Three steps here:
- s/\w/a x 2**(-97+ord$&)/ge;
converts the input into a string of a
only.
- s/(.*)-\1|+//;/*/&&($_=$`x length$')
will execute the operator (that are very simple on strings of a
): +
is the concatenation, -
means removing from the first part as many a
as there are in the second part, and *
means duplicating the first part as many times as there are a
in the second part.
- 1while s/(.)\1/chr 1+ord$1/e
folds the consecutive same letters into the next letter in the alphabet.