Skip to main content
saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (Node.js),  80 66 65 58  5857 bytes

s=>Buffer(s).map(c=>c%3?i^=~c:a[c+i++&1]+=.5a[c&1]+=++i&1,a=[i=0,0])&&a

Try it online!Try it online!

##How###How?

###Identifying the characters

###Counting the mice

Instead of counting 'whole mice' we add \$1/2\$ to the relevant counter for each mouse body part.

##Commented###Commented

s =>                        // s = input string
  Buffer(s)                 // turn s into a buffer
  .map(c =>                 // for each ASCII code c:
    c % 3 ?                 //   if c modulo 3 is not equal to 0:
      i ^= ~c               //     invert the least significant bit of i if c is even
                            //     (must be 80, for 'P')
    :                       //   else:
      a[c + i++ & 1] += .5++i & 1, //     add 1/2 to a[i &update 1]a[0] if c is even (126 -> '~')
                            //     or to a[(i ^ 1) & 1]a[1] if c is odd (111 -> 'o')
                            //     increment i and add its parity
    a = [i = 0, 0]          //   start with a = [0, 0] and i = 0
  ) && a                    // end of map(); return a[]

JavaScript (Node.js),  80 66 65  58 bytes

s=>Buffer(s).map(c=>c%3?i^=~c:a[c+i++&1]+=.5,a=[i=0,0])&&a

Try it online!

##How?

###Identifying the characters

###Counting the mice

Instead of counting 'whole mice' we add \$1/2\$ to the relevant counter for each mouse body part.

##Commented

s =>                        // s = input string
  Buffer(s)                 // turn s into a buffer
  .map(c =>                 // for each ASCII code c:
    c % 3 ?                 //   if c modulo 3 is not equal to 0:
      i ^= ~c               //     invert the least significant bit of i if c is even
                            //     (must be 80, for 'P')
    :                       //   else:
      a[c + i++ & 1] += .5, //     add 1/2 to a[i & 1] if c is even (126 -> '~')
                            //     or to a[(i ^ 1) & 1] if c is odd (111 -> 'o')
                            //     increment i
    a = [i = 0, 0]          //   start with a = [0, 0] and i = 0
  ) && a                    // end of map(); return a[]

JavaScript (Node.js),  80 66 65 58  57 bytes

s=>Buffer(s).map(c=>c%3?i^=~c:a[c&1]+=++i&1,a=[i=0,0])&&a

Try it online!

###How?

###Commented

s =>                       // s = input string
  Buffer(s)                // turn s into a buffer
  .map(c =>                // for each ASCII code c:
    c % 3 ?                //   if c modulo 3 is not equal to 0:
      i ^= ~c              //     invert the least significant bit of i if c is even
                           //     (must be 80, for 'P')
    :                      //   else:
      a[c & 1] += ++i & 1, //     update a[0] if c is even (126 -> '~')
                           //     or a[1] if c is odd (111 -> 'o')
                           //     increment i and add its parity
    a = [i = 0, 0]         //   start with a = [0, 0] and i = 0
  ) && a                   // end of map(); return a[]
removed the previous version and updated the explanation
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (Node.js),  80 66 65  58 bytes


JavaScript (Node.js),  80 66  65 bytes

Returns [towards, away].

s=>Buffer(s).map(c=>+s?s=0:c%3?p|=~c&1:s=++a[p^c&1],a=[0,p=0])&&a

Try it online! ##How?

###How?###Identifying the characters

###Commented###Counting the mice

Instead of counting 'whole mice' we add \$1/2\$ to the relevant counter for each mouse body part.

##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:
   c % 3 s? = 0               //   if c ignoremodulo this3 character;is setnot sequal to 0:
    :    i ^= ~c               //   else:
      c % 3 ?           invert the //least significant bit of i if c modulo 3 is not equal to 0:even
        p |= ~c & 1       //       set p to 1// if c is even (must be 80, for 'P')
    :  :                   //  //   else:
        s =        a[c + i++ & 1] += .5, //       setadd s1/2 to a positive numeric value,
     a[i & 1] if c is even (126 -> '~')
            //       so that the next character is ignored
   //     or to ++a[pa[(i ^ c1) & 1], //       increment a[p] if c is evenodd (126111 for-> '~''o')
                          //       or p[p ^ 1] if// c is odd (111 forincrement 'o')i
    a = [0, p[i = 0, 0]          //   start with a = [0, 0] and pi = 0
  ) && a                    // end of map(); return a[]

JavaScript (Node.js), 58 bytes


JavaScript (Node.js),  80 66  65 bytes

Returns [towards, away].

s=>Buffer(s).map(c=>+s?s=0:c%3?p|=~c&1:s=++a[p^c&1],a=[0,p=0])&&a

Try it online!

###How?

###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 % 3 ?             //     if c modulo 3 is not equal to 0:
        p |= ~c & 1       //       set p to 1 if c is even (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),  80 66 65  58 bytes

##How?

###Identifying the characters

###Counting the mice

Instead of counting 'whole mice' we add \$1/2\$ to the relevant counter for each mouse body part.

##Commented

s =>                        // s = input string
  Buffer(s)                 // turn s into a buffer
  .map(c =>                 // for each ASCII code c:
    c % 3 ?                 //   if c modulo 3 is not equal to 0:
      i ^= ~c               //     invert the least significant bit of i if c is even
                            //     (must be 80, for 'P')
    :                       //   else:
      a[c + i++ & 1] += .5, //     add 1/2 to a[i & 1] if c is even (126 -> '~')
                            //     or to a[(i ^ 1) & 1] if c is odd (111 -> 'o')
                            //     increment i
    a = [i = 0, 0]          //   start with a = [0, 0] and i = 0
  ) && a                    // end of map(); return a[]
added a shorter version
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

JavaScript (Node.js), 58 bytes

Returns [towards, away].

s=>Buffer(s).map(c=>c%3?i^=~c:a[c+i++&1]+=.5,a=[i=0,0])&&a

Try it online!


JavaScript (Node.js),  80 66  65 bytes

JavaScript (Node.js),  80 66  65 bytes

JavaScript (Node.js), 58 bytes

Returns [towards, away].

s=>Buffer(s).map(c=>c%3?i^=~c:a[c+i++&1]+=.5,a=[i=0,0])&&a

Try it online!


JavaScript (Node.js),  80 66  65 bytes

saved 1 byte
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
fixed formatting
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
added a commented version
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
the version without error checking is now the main one
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
saved 10 and 14 bytes respectively
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading
Source Link
Arnauld
  • 197.7k
  • 20
  • 179
  • 650
Loading