Skip to main content
4 of 9
added a commented version
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (Node.js),  80  66 bytes

Returns [towards, away].

s=>Buffer(s).map(c=>+s?s=0:c<96?p|=c<95:s=++a[p^c&1],a=[0,p=0])&&a

Try it online!

###Commented

s =>                      // s = input string
  Buffer(s)               // turn s into a buffer
  .map(c =>               // for each ASCII code c:
    +s ?                  //   if s is a positive numeric value:
      s = 0               //     ignore this character; set s to 0
    :                     //   else:
      c < 96 ?            //     if c is less than 96:
        p |= c < 95       //       set p to 1 if c < 95 (must be 80, for 'P')
      :                   //     else:
        s =               //       set s to a positive numeric value,
                          //       so that the next character is ignored
          ++a[p ^ c & 1], //         increment a[p] if c is even (126 for '~')
                          //         or p[p ^ 1] if c is odd (111 for 'o')
    a = [0, p = 0]        //    start with a = [0, 0] and p = 0
  ) && a                  // end of map(); return a[]

JavaScript (Node.js),  112  102 bytes

A version with error checking, as per the original rules of the challenge.

s=>Buffer(s).some(c=>n?n-=c:c-111&&c-126?c-95?c-80|p++:0:!++a[n=c^17,p^c&1],a=[n=0,p=0])|p-1?'error':a

Try it online!

Arnauld
  • 197.7k
  • 20
  • 179
  • 650