C (gcc), 117 113 bytes
i;f(char*p){for(i=0;p[i++]-40||p[i+3]-41;);p[i-1]=p[i+1]-62?p[i]:p[i+2];memcpy(p+i,p+i+4,strlen(p));*p-40||f(p);}
Takes an input string with enclosing in parentheses and reduces the input string to either a left (<
) or a right (>
).
Explanation
i;f(char*p){ // function taking a string parameter p
for(i=0;p[i++]-40||p[i+3]-41;); // loop until we find chars '(' and ')'
// separated by 3 characters.
// since our input is enclosed in
// parentheses we will always find one.
p[i-1]= // i has gone forward one but set the
// first of these characters - the '('
// to...
p[i+1]-62? // ...depending on whether the middle
// char is a '<'...
p[i]: // ...the one before the middle if '<'
p[i+2]; // ...the one after the middle if '>'
memcpy(p+i,p+i+4,strlen(p)); // move the back end of the string forward
// over the other 4 chars.
// now a "(A<B)" is reduced to "A"
// and a "(A>B)" is reduced to "B"
*p-40|| // if the string now starts with a '('
f(p); // recursively call f.
// otherwise p is now reduced to the
// answer and we're done.
}