Indexing Cha-Cha Slide

Ruby, 98 ... 58 55 bytes

->a{([*0..a[-1]]-a).sum{|c|-1i**(m[c%55].ord%19)}.rect}

Try it online!

Explanation:

The main trick is using complex numbers to represent moves: 'B' is -i, 'H' is +i, 'L' is -1 and 'R' is +1. If we convert all the moves into complex numbers, then with a single sum we get the right result.

I tried different ways, but then I found the magic number 19: we don't need to fiddle with regex matching because:

B  is ASCII 66; 66%19=9  and i^9  = i
H  is ASCII 72; 72%19=15 and i^15 =-i
L  is ASCII 76; 72%19=0  and i^0  = 1
R  is ASCII 82; 82%19=6  and i^6  =-1

So, put that all together, sum, invert the sign, and we're done.

Thanks Jakob for -3 bytes


05AB1E, 15 12 bytes

Saved 3 bytes thanks to Erik the Outgolfer

ÝsKèIêRS¢2ôÆ

Try it online! or as a Test suite

Explanation

Ý                 # push range [0 ... input_int]
 sK               # remove all elements in input_list from this range
   è              # cyclically index into the moves-list with the remaining elements
    Iê            # push the unique chars of the move-list, sorted
      R           # reverse
       S¢         # count the occurrences of each char in "RLHB"
         2ô       # split into 2 parts
           Æ      # reduce each part by subtraction

JavaScript (ES6), 85 bytes

As per the challenge rules, this code expects the global-scope string m to hold the list of moves. (Saving 3 bytes, as suggested by @KevinCruijssen.)

Takes input as a list of 0-based indices, ordered from lowest to highest.

a=>a.map(g=i=>j++<i&&g(i,p=m.search(m[~-j%55])*3%5,x+=--p%2,y-=--p%2),j=x=y=0)&&[x,y]

Try it online!

How?

Each move character is converted to its position in the move string "LBHR...". We multiply the result by 3 and apply a modulo 5, which gives p. We then have:

  • dx = ((p-1) mod 2)
  • dy = -((p-2) mod 2)

Where the sign of a mod b is that of a.

 character | position | * 3 | mod 5 | dx | dy
-----------+----------+-----+-------+----+----
    'L'    |     0    |  0  |   0   | -1 |  0
    'B'    |     1    |  3  |   3   |  0 | -1
    'H'    |     2    |  6  |   1   |  0 | +1
    'R'    |     3    |  9  |   4   | +1 |  0