left and right, to the start and end of the string respectively.left until a car that is not moving left ('L') is found.right until a car that is not moving right ('R') is found.collisions to 0 to count the number of collisions.left to right.
rightMovingCars.rightMovingCars to collisions (plus one more if the car is moving left).rightMovingCars to 0 after each collision.