Skip to main content
4 of 17
added 17 characters in body
Noodle9
  • 20.3k
  • 3
  • 21
  • 46

C (gcc), 117 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));i=*p-40?*p:f(p);}

Try it online!

Takes an input string with enclosing in parentheses and returns whether it's left (<) or 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 one forward, but set the 
                                   // first of these characters  - the '('  
                                   // to...     
          p[i+1]-62?               // ... depending on whether the middle   
                                   // char is a '<' ...   
                    p[i]:          // the first if '<'
                         p[i+2];   // the second if '>'  
  memcpy(p+i,p+i+4,strlen(p));     // move the rest of the string back over  
                                   // the other 4 chars.    
  i=                               // return ...
    *p-40?                         // ... depending on whether the string now  
                                   // starts with a '(' ...   
          *p:                      // the first char if not since we're done  
             f(p);                 // or recursively call f if it does.
}  
Noodle9
  • 20.3k
  • 3
  • 21
  • 46