[Question]
  [
Given a position with a row of rooks and/or empty spaces, output how many different rook moves are possible. A rook can move left or right to an empty space, but not to one that requires passing over another rook. When a rook moves, the other rooks remain in place.
For example, from this position, **6 moves** are possible:
```
.R..RRR.
```
* The first (leftmost) rook can move 1 space left, or 1 or 2 spaces right (3 moves)
* The next rook can only move 1 or 2 spaces left (2 moves)
* The third rook cannot move at all because it's squeezed between two other rooks (0 moves)
* The last rook can only move 1 space right (1 move)
Note that a position might have no rooks at all, or no empty spaces at all.
**Input:** A non-empty list (string, array, etc..) of rooks and empty spaces. You can represent them as `True`/`False`, `1`/`0`, `'R'`/`'.'`, or any two consistent distinct single-byte characters or one-digit numbers of your choice. It's up to you which one means rook and which means empty space.
**Output:** A non-negative integer. Whole-number floats are also fine.
**Test cases**
The output is the number on the left.
```
6 .R..RRR.
0 .
0 R
4 R..RR
3 ...R
8 ..R..R..
0 ......
```
For more test cases, here are all inputs up to length 5.
```
0 .
0 R
0 ..
1 .R
1 R.
0 RR
0 ...
2 ..R
2 .R.
1 .RR
2 R..
2 R.R
1 RR.
0 RRR
0 ....
3 ...R
3 ..R.
2 ..RR
3 .R..
3 .R.R
2 .RR.
1 .RRR
3 R...
4 R..R
3 R.R.
2 R.RR
2 RR..
2 RR.R
1 RRR.
0 RRRR
0 .....
4 ....R
4 ...R.
3 ...RR
4 ..R..
4 ..R.R
3 ..RR.
2 ..RRR
4 .R...
5 .R..R
4 .R.R.
3 .R.RR
3 .RR..
3 .RR.R
2 .RRR.
1 .RRRR
4 R....
6 R...R
5 R..R.
4 R..RR
4 R.R..
4 R.R.R
3 R.RR.
2 R.RRR
3 RR...
4 RR..R
3 RR.R.
2 RR.RR
2 RRR..
2 RRR.R
1 RRRR.
0 RRRRR
```
  
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~14~~ 9 bytes
```
w`_+R|R_+
```
[Try it online!](https://tio.run/##K0otycxLNPyvquGe8L88IV47qCYoXvv///ig@PigoKB4rniuIC4wmyseSAKJIDAC8YAAAA "Retina – Try It Online") Link includes test cases. Uses `_` for empty space as it's the most pleasant non-regex character. Works by counting the number of substrings that correspond to a valid Rook move. A substring is a valid Rook move if it contains at least one `_` plus a single `R` at either the beginning or the end.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~30~~ 29 bytes
```
lambda s:sum((s+s).strip())/9
```
[Try it online!](https://tio.run/##RY5Ra8MgFIXf/RUXX6osbIGOsQZ8GGUPexr42pSRpEoDrRHvDUsJ@@2ZmrGqD@c7nuPV3@g8uO1iVb1cmmt7agArHK9C4APKR6TQeyHl024hg/TVNWgQFByYeCmAgwbQWgOXBRNlMv6Vzuo5qZTJtE2JSBleM@h87v28Eh4Zs0MAM/kCEHoH9/kVS6E2fqO9RVccymkHvYUOlIJN3OaCBkpI/S5V8ShzZRgplqxoV2wQTaDVVesky2v34fxIVQrM@FO7z5H@eI7JaLxP3nRkThXMsRMNnl/zoXck@H4IIV7Dm8NvE7hcfgE "Python 3 – Try It Online")
*-1 byte thanks to @JoKing*
The function takes a Python byte string as input. Each empty space is encoded as a tab and each rook is encoded as a byte `b'\x00'` having value `0`. 
The computation is equivalent to `lambda s:(s+s).strip().count(b'\t')` while having a lower byte count.
[Answer]
# JavaScript (ES6), ~~38~~ 33 bytes
*Saved 5 bytes thanks to @JoKing*
Takes input as a string. Expects a space for an empty square and any other character for a rook.
```
s=>(s+s).trim().split` `.length-1
```
[Try it online!](https://tio.run/##dc1BDsIgEAXQfU/xd4WYUo3GuKGH4ARtKq0YLE2H9PoIBnQlmQ1vZv48h32gcTOrbxZ312GSgWTH6EBc@M28GBe0WuN79MLqZfaP5hS8Jg8JguwwuoWc1cK6mU2MOK@q1GY1FKCUQs2BtsW1cPrnF/mYWf3hlJFbkS8lJHJZiHz@svpUPnn7TQP5bsoObw "JavaScript (Node.js) – Try It Online")
### Commented
```
s =>          // s = input, e.g. " R  RRR "
  (s + s)     // double -> " R  RRR  R  RRR "
  .trim()     // remove leading and trailing spaces -> "R  RRR  R  RRR"
  .split` `   // split on spaces -> [ 'R', '', 'RRR', '', 'R', '', 'RRR' ]
  .length - 1 // return the length - 1 -> 6
```
---
# [Python 2](https://docs.python.org/2/), ~~40~~ 33 bytes
*Saved 7 bytes thanks to @Grimy*
```
lambda s:(s+s).strip().count(' ')
```
[Try it online!](https://tio.run/##LY2xDsIwDER3vuLUxbZadWCsxE94BYYWFBEJkigOA18f0sDJuju9G5w@5RHDsbrTpT7X13ZfYQvbaDJbyT6xzLf4DoUJJNXFDIMPOBMUUFXQBOqm3XbYUSu/1H5/1kTXBSn7UNAesGMTwdjGgVrYXgeqhy8 "Python 2 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
²x èS
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=sngg6FM&input=IiBSICBSUlIgIg)
```
²x èS        Implicit input string of U
²            U + U
 x           Remove trailing and leading whitespace
   èS        Number of spaces
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 16 bytes
```
{+m:ex/s+R|Rs+/}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv1o71yq1Qr9YO6gmqFhbv/a/NVdOZl5qsV5uYoGGlp5aml5xYqXm/@Kg4uKgoKBirmKuIC4wm6sYSAKJIDAC8YCACwA "Perl 6 – Try It Online")
A regex that matches all exhaustive instances of rooks followed by spaces, or spaces followed by a rook and returns the number of matches.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
«ðÚð¢
```
[Try it online!](https://tio.run/##yy9OTMpM/f//0OrDGw7POrzh0KL//xUUAA "05AB1E – Try It Online")
```
«       # concatenate the input with itself
 ðÚ     # remove leading and trailing spaces
   ð¢   # count spaces
```
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~23~~ 15 bytes
Double the number of spaces between rooks, grep lines with at least one rook, then count the number of spaces.
```
R.+R
$0$0
G`R
 
```
[**Try it online!**](https://tio.run/##K0otycxLNPyvquGewBWjx6XwP0hPO4hLxUDFgMs9IQjI/68XpKcXFBSkx6XHFcQFZnPpAUkgEQRGIJ4eiAoCQwA "Retina – Try It Online")
Though the program uses spaces instead of periods, I added prefix code so that the test cases provided may be easily pasted in and used.
I was hoping I could use overlapping matches with `(?<=R.*) | (?=.*R)`, but overlaps aren't quite that aggressive. It would need to count all possible ways a match could be obtained in order to return the correct result with that method.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
t1;ḟẠS
```
[Try it online!](https://tio.run/##PU8rDkIxEPQ9RSUIGv7mBQ4xKA6AIUgMwRAMHoWAQDAkBEUQD5AvHKTvIqXdT0V3d7qfmZnPFotVCMtO4cuz/1wm4bf370NRb462Nbb15lRUuzXBRgKxOjWNL5/@fR/F2lU3X16N/76qXb19TENoW2faFvE5ZzrWIQbQF/85040RKYIHUg36B0/LuMw700sJlCDrhMA9yDU9l3pIe/2UGEHOE5eQKZvSKV9adMRIGSqAMaQPVZQlUZ@IB5QFQ0WyZhWdVWfZYMGxP6SMeAfEz0a4DzEGdZatEVbj6lytZ@9qPrvP9vEH "Jelly – Try It Online")
A monadic link taking a list of `0` for rook and `1` for space and returning an integer with the number of moves. The TIO link takes the pasted list of possible boards given in the question, converts to the right format and then outputs the calculated and correct answers. 
## Explanation
```
t1     | Trim 1s from end
  ;    | Concatenate to input
   ḟẠ  | Filter out 1s if all input were 1s, otherwise filter out 0s
     S | Sum
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Spaces for spaces, any other character for rooks.
```
²x ¸ÊÉ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=sngguMrJ&input=IiBSICBSUlIgIg)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~43~~ 38 bytes
```
Count[Subsequences@#,{0,1..}|{1..,0}]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73zm/NK8kOrg0qTi1sDQ1Lzm12EFZp9pAx1BPr7amGkjqGNTGqv0PKMoEKlPWtUtzUI5V03eo5qo21AGq0gGRIGhYqwMUAhEGYAImBRaGcGBMmJwhVJMOHNZy1f4HAA "Wolfram Language (Mathematica) – Try It Online")
Port of [Neil's Retina solution](https://codegolf.stackexchange.com/a/191192/81203). Uses 1 for spaces and 0 for rooks.
[Answer]
# Snails, 7 bytes
At least it beats Retina :)
```
o
\.+\R
```
[Try it online!](https://tio.run/##K85LzMwp/v8/nytGTzsm6P9/vSA9vaCgID0A "Snails – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
ḲẈ+ƝS
```
[Try it online!](https://tio.run/##y0rNyan8///hjk0Pd3VoH5sb/P//f3U9BT09BQUFPXUA "Jelly – Try It Online")
-1 thanks to [Jonathan Allan](https://codegolf.stackexchange.com/users/53748/jonathan-allan).
`0` represent a rook, `1` represents an empty space.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 7 6 5 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
àσQ█ε
```
[Run and debug it](https://staxlang.xyz/#p=85e551dbee&i=%22%09R%09%09RRR%09%22%0A%22%09%22%0A%22R%22%0A%22R%09%09RR%22%0A%22%09%09%09R%22%0A%22%09%09R%09%09R%09%09%22%0A%22%09%09%09%09%09%09%22&m=2)
Use tab for empty square and any other character for rook.
[Answer]
# [C (clang)](http://clang.llvm.org/), 57 bytes
```
i,r,o;g(*n,z){for(o=r=i=0;z--;i=-~i*!*n++)o+=*n?r=1,i:r;}
```
[Try it online!](https://tio.run/##fc7RDoIgFAbge57Cam2oxwaWF0XUg1RrTcvOVodGdZOzVzezWXmhMGA733@AOIhPO0oLpJtDq43OJIhy1nt15opVvBV14LeaAfkOtPeHH24gyC@P6@5mefL71v9l0X/6XWYFggWjUu4RPNzsYCw32mrUQj2CQKEOnuj1PPJ91/jao6XVEnBmVV6wAVJ8uid7Z369JWhGx0X1zHmHxF0nYyknkMJV7GLL@sHh/WGypj6YslTaVnSqhGk7hl04hqgdJ10YtWE18uIF "C (clang) – Try It Online")
* Saved 1 thanks to @ceilingcat
I realized it didn't worked for empty lists..
Now it works! Plus saved some bytes!
1=rook. 0=space.
for(.. i+=*n++?-i:1)// counts spaces or reset extra moves => i=-~i*!\*n++ ( @ceilingcat )
o+=\*n?r=1,i:r; // adds to output -i-(extra moves) when a rook is met plus sets -r-(rook met), -i- will be cleared in for increment sentence.
adds -r- for every space(rook met guaranteed )
[Answer]
# [Haskell](https://www.haskell.org/), 36 bytes
```
f s=sum$snd.span(>0)=<<[s,reverse s]
```
[Try it online!](https://tio.run/##JYjBCsMgGIPvPkWQgi10pbvXPcR/LT1Ip1uZFfHv9vhz2oUkH8nT8Mt6n7MDa37vDYf7wNGE9jZ2eppm7pP92MQWvGSGgtJXUUhKj0LsZgvQiGkLBxrsJrZuKA3uypwlCCAiyF7WUE196i48Qaf/T5Fc8nd13jw4X9YYfw "Haskell – Try It Online")
Uses 1 for empty space, 0 for rook. Counts the number of 1's not in an initial block of ones, and adds that to the result for the reversed string.
[Answer]
# [Haskell](https://www.haskell.org/), 33 bytes
```
sum.(t.reverse<>t)
t=snd.span(>0)
```
[Try it online!](https://tio.run/##JYvBDsIgEETvfMWGmBQSJfVeevLqhat62LRUiYUSFv18EXSysy8zyTyQnnZdi/NxSxlOmFGdt7C5GYQYRinZAhquhV5eiaySfdtEdhizZFlTmBVFDGLsZSHooNNHVmk63TPm0YW6jcmFDDvwGMWi6geSNV44GABjDPA9bzbNrWm58gfzu39TxW/lMy0r3qkcphi/ "Haskell – Try It Online")
Anonymous function that takes input as a list of 1s (spaces) and 0s (rooks). This trims spaces from the start and the end of the list, then concatenates the two versions of the list and sums them. 
This uses GHC 8.4.1 or later to have access to the `<>` operator without importing it.
[Answer]
# [Python 2](https://docs.python.org/2/), 59 bytes
```
def f(r):S=map(len,r.split('R'));return sum(S)*2-S[0]-S[-1]
```
[Try it online!](https://tio.run/##LY5BDsIgEEXX9hSzGzCUaJc1XmJYNixMhEjSUjLQhadHRCc/7/@81aR3ee1xqvXpPHjBcjb37ZHE6qJindMaikBCKW/sysER8rEJI8/TaJaLbRivtvqdIUOIsKAmrYlIowLsoI6v7KqNX1PP37VDOw@nxCEWyKp9kmUdPg "Python 2 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
²x ¸ÊÉ
```
[Try it online](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=sngguMrJ&input=IiBSICBSUlIgIg)
[Answer]
# [Haskell](https://www.haskell.org/), ~~68~~ ~~58~~ 54 bytes
```
(n#y)(a:x)|a<1=n+(0#1)x|m<-n+1=y+(m#y)x
(_#_)x=0
f=0#0
```
[Try it online!](https://tio.run/##RYrLCsMgEEX3foXEQBTbQbdF@xGzLSW4aGholFC7MJB/t9NHWhg499w715Bvl2mqVSaxKBkORa3BWZ@0NMKqska3T9r6RctID4XJXvSqeMMGb4SpmXfQecuI2FEbw5j8fB/To5UDxDDzrFx7ZJyfeAMIgIjQkO5Iv8SNr3XbKP8ivu@/wEfO9Qk "Haskell – Try It Online")
[Answer]
# [Red](http://www.red-lang.org), 46 bytes
```
func[s][length? next split trim append s s sp]
```
[Try it online!](https://tio.run/##XYw7DoAwDEN3TmH1GCzcIWvVAdEUKkEUtUHi9kWw8LEnP1suHBtx9KFLPVraZfI1@JVltmWA8GGoumaDlbxhVGWJqJc1NC1ZDAkOBBARXPegm@GN7tE345e/F@/ukmsn "Red – Try It Online")
Just a [Red](http://www.red-lang.org) port of [Arnauld's JavaScript/Python solutions](https://codegolf.stackexchange.com/a/191182/75681). Takes a space as an empty square.
[Answer]
# Java 11, ~~35~~ 32 bytes
```
s->(s+s).strip().chars().sum()/9
```
Port of [*@Joel*'s Python 3 answer](https://codegolf.stackexchange.com/a/191195/52210).  
-3 bytes thanks to *@Joel* as well.
Uses NULL-bytes (`\0`) for Rooks and tabs (`\t`) for spaces.
[Try it online.](https://tio.run/##bVHBbsIwDL3zFVZOiTpCrxsaf8AuHMcOIWRboA1R7SKhiW8vbhoEqyorjvzs5xc7B3M288P@2NnKIMLa@PA3A/CBXPNtrIMP6OOEgJUbanz4AVRLBq8zdkiGvOWyAO/Q4XwlsUClkQujVNr@mgb5xraWavHaLXtObHcVczL1fPJ7qFk4d//8AqMGUXJIUmxpW/LpfW8kkvojO4rLcXznjnkDPoGWDz/JoYlMebdJ9X9az3tLw6fSvFofYkt5/M0FydX61JKOnKQqyJTWjYsVf04a9kVw2yeEGOHHFeINRBG0HSgqK1@7Gw)
I tried using `s->(s+s).trim().chars().sum()/9` at first as 31-byter, but this doesn't work because the [`String#trim` builtin](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#trim()) not only removes leading and trailing spaces/tabs/newlines, but also all other bytes that are smaller than or equal to `U+0020` (unicode 32; a space), so it'll remove the NULL-bytes as well..  
Thanks to *Joel* for recommending me the new Java 11+ [`String#strip` builtin](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#strip()) (which I forgot they added) as alternative. This one also removes trailing/leading portions, but in this case only [whitespaces](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Character.html#isWhitespace(int)), so the NULL-bytes are retained.
**Explanation:**
```
s->                              // Method with String as parameter & integer return-type
  (s+s)                          //  Concatenate the input to itself
       .strip()                  //  Then trim all leading and trailing tabs
               .chars().sum()    //  Sum the unicode values of the remaining characters
                             /9  //  And divide it by 9 to get the amount of remaining tabs
```
[Answer]
# [Perl 5](https://www.perl.org/) `-MList::Util=sum -pF/R/`, 40 bytes
```
$\=2*sum map$_=y///c,@F}{$\-="@F"+$F[-1]
```
[Try it online!](https://tio.run/##K0gtyjH9/18lxtZIq7g0VyE3sUAl3rZSX18/WcfBrbZaJUbXVsnBTUlbxS1a1zD2/389vSAw@pdfUJKZn1f8X9fXJ7O4xMoqtCQzxxZoBFDAVM/A0OC/boGbfpA@AA "Perl 5 – Try It Online")
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 27 bytes
```
x=>(x+x).Trim().Sum(d=>d)/9
```
Saved a byte thanks to @someone
[Try it online!](https://tio.run/##RcyxCsIwEIDhvU9x3HSHNbpKTUYf4BRcutQklYBNJUmlbx@hDq4f/L/Ne5tDvSzRnnNJIT7bEIsZdV21oXW3srqlMBGr6zKR08bx4VS75jMHB8XnQr8KHvOQHIM2cE@heBppEyX@/RqsJxRsAfsj8p8AW@wLMnPXNNsMQQBEBJC7@gU "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~7~~ 6 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
-1 byte thanks to recursive
```
╣ë|óêπ
```
[Run and debug it](https://staxlang.xyz/#p=b9897ca288e3&i=%22+R++RRR+%22%0A%22+%22%0A%22R%22%0A%22R++RR%22%0A%22+++R%22%0A%22++R++R++%22%0A%22++++++%22&m=2)
[Answer]
# [Befunge-98 (PyFunge)](https://pythonhosted.org/PyFunge/), 73 bytes
```
#;ep10fp#;>#v~:'.-#v_$1+0k
v0+ge0*gf0$_v#!-R':<
>ep20fp   v >0fg1-*0eg+.@
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz//9Xtk4tMDRIK1C2tlMuq7NS19NVLotXMdQ2yOYqM9BOTzXQSk8zUIkvU1bUDVK3suGySy0wAipXUFAoU7AzSEs31NUySE3X1nP4/18vSE8vKChIDwA "Befunge-98 (PyFunge) – Try It Online")
[Answer]
## [C](https://en.wikipedia.org/wiki/C_%28programming_language%29), 183 156 151 ~~137~~ ~~96~~ 91 bytes
Thanks to ceilingcat for 91 bytes.
```
c,e;char*z,b[9];main(d){for(gets(z=b);e=*z>81?c-=e*~!d,d=0:e+1,*++z;);printf("%i",d?:c+e);}
```
R is a rook, everything else is a space.
[TIO](https://tio.run/##BcFLDoIwEADQu5CY9DNt7E6ZjNyhW@MCpgN2IZrKqgSvXt9jtzC3xpBAkJ9jMRWm@/WBrzGvSu/zu6hFtq@qNGkUMvV2CQM7EvNLkCjAuRcbwFhbUeOn5HWbVXfKHbClNEjvWOPRmo/exxj9Hw)
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 7 bytes
```
/r6*2Qd
```
[Try it online!](https://tio.run/##K6gsyfj/X7/ITMsoMOX/f6UgBYWgICUA "Pyth – Try It Online")
Takes a string of `R` for rooks,  (space) for empty spaces
```
/     d  # Count spaces in
 r6      #  Strip spaces from
   *2Q   #   2 * input() (= concatenation)
```
[Answer]
# x86-64 - 26 Bytes
Input is an array of up to 32 bits and an integer representing number of squares, 1 representing rook, 0 representing empty.
```
C4 E2 69 F7 C1       shlx        eax,ecx,edx
0B C1                or          eax,ecx  
F3 0F BC C8          tzcnt       ecx,eax  
D3 E8                shr         eax,cl  
F3 0F BD C8          lzcnt       ecx,eax  
F7 D0                not         eax  
F3 0F B8 C0          popcnt      eax,eax  
2B C1                sub         eax,ecx  
C3                   ret  
```
Copies the bits so that it is added to the left of it and removes the trailing zero bits. Then gets number of leading zero bits and subtracts it from the total number of zero bits.
# x86-64 Machine Code - 22 Bytes - regular length chess ranks only.
Input is a 32-bit integer with the least significant byte made of 8 bits representing the rooks. 1 is a rook, 0 is empty.
```
8A E9                mov         ch,cl  
91                   xchg        eax,ecx
F3 0F BC C8          tzcnt       ecx,eax
D3 E8                shr         eax,cl 
F3 0F BD C8          lzcnt       ecx,eax
F7 D0                not         eax  
F3 0F B8 C0          popcnt      eax,eax
2B C1                sub         eax,ecx
C3                   ret  
```
Copies the bits into the next significant byte and removes the trailing zero bits. Then gets number of leading zero bits and subtracts it from the total number of zero bits.
]