board. It holds exactly one white rook 'R', some white bishops 'B' and some black pawns 'p'; empty squares are '.'.
The rook moves in a straight line, up, down, left or right, any number of squares, but it cannot jump over pieces: its path ends at the first occupied square or at the edge of the board. A pawn is under attack if the rook can land on its square in one move, which means the pawn is the first piece in one of the four directions.
Return how many pawns the rook is attacking right now.board=[[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", "p", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", "p", "B", ".", "R", ".", "p", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", "B", ".", ".", "."], [".", ".", ".", ".", "p", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]] → 2
The rook is at row 3, column 4. Upward there is a pawn, and to the right there is a pawn. To the left a bishop comes first and shields the pawn behind it; downward there is a bishop too. The answer is 2.
board=[["R", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], ["p", "p", ".", ".", ".", ".", ".", "."]] → 1
The rook sits in a corner. The pawn in the bottom-left corner shares its column with nothing in between; the other pawn is off the rook's lines. The answer is 1.
board has 8 rows of 8 squares'R', 'B', 'p' or '.''R'board=[[".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", "p", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", "p", "B", ".", "R", ".", "p", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", "B", ".", ".", "."], [".", ".", ".", ".", "p", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."]]
2
Run checks the first 3 tests in your browser. Submit checks all 60 tests on the server, hidden ones included.