How many ways can 2 rooks and a bishop be placed on a 4x4 board such that no piece attacks another piece?

225 Views Asked by At

How many ways can $2$ rooks and a bishop be placed on a $4\times 4$ board such that no piece attacks another piece?

I stumbled upon this question and I don't know how to find the answer mathematically. I wrote this piece of code to find the answer to it. I think the code is right, but I get the answer as $232$, which doesn't "feel" right. So how do you actually go about solving this question?

3

There are 3 best solutions below

2
On BEST ANSWER

Brute force.

Observation : The bishop can be treated as a queen! We place Q first, then two identical rooks R1, R2.

There are three kinds of squares : corner (4), edge (8), center (4). We place first Q on each type and then two rooks.

Center : Q clears a $3\times 3$ grid and one more corner and two edge squares. Only four squares remain. Total $:4\cdot 2\cdot 2=16$ ways.

Corner : Q clears two edges and one diagonal. Six squares remain. Choosing any one of these six for R1 leaves three squares out for R2. Total $:(4\cdot 6\cdot 3)/2=36$

Edge : Q clears an edge and a row/column and three more on its two diagonals. Six squares remain. If R1 is anywhere on one of three squares of an outer edge, it gives $2$ choices each for R2. Other three squares are at a knight's distance from Q. R1 on lonely square leaves 4 choices for R2. R1 on other pair of squres leaves $3$ choices each for R2. Total $$8\times \frac{3\cdot 2+4+2\cdot 3}{2}=64$$

Grand total $: 16+36+64=116$

3
On

I'm not sure there is a way to solve the problem without a good deal of brute force. It's pretty easy to calculate the number of ways to place two rooks that don't attack each other (You can choose the two rows in $4\choose2$ ways and the columns associated with them in another $4\cdot 3$), but then analyzing how to add a bishop would require at least some subcases and probably quite a lot.

2
On

Here is my Basic code (17 lines, including comments). It prints $116$, so it looks like you are treating the two rooks as different.

Private R1X, R1Y, R2X, R2Y, BX, BY
Private Counter = 0

For R1X = 1 To 3 : For R2X = R1X + 1 To 4
  For R1Y = 1 To 4 : For R2Y = 1 To 4
    If R2Y <> R1Y Then
      For BX = 1 To 4 : For BY = 1 To 4
        If BX <> R1X And BX <> R2X And BY <> R1Y And BY <> R2Y Then
          Rem  A bishop at (BX,BY) attacks a piece at (X,Y) if
          Rem  Abs(BX-X) = Abs(BY-Y):
          If Abs(BX - R1X) <> Abs(BY - R1Y) And Abs(BX - R2X) <> Abs(BY - R2Y) Then
            Counter = Counter + 1
          End If
        End If
      Next BX, BY
    End If
Next R1X, R1Y, R2X, R2Y

Print Counter