5

I was thinking about asking this is chat because I thought that my concern is not serious enough, but it became too long so here I am.

I hope that the question is clear: you just can't place rooks on squares with coordinates $(1, 1), 2, 2)$ and so on. I will call these squares forbidden. For small board sizes the answer is: 2x2 - 1, 3x3 - 2, 4x4 - 9 (if I haven't made a mistake which I'm not so sure about).

This problem is harder than it felt at the first glance. What makes it harder is the fact that after placing a rook on the 1st line and figuring out ways for all the lower lines, these lower lines are not equal: one of them already has forbidden square on a column on which you placed the 1st line rook, so nothing is changed for this line, but for other lines you have lessen the number of vacant places by one. To make it more clear, think of coordinates as index of a matrix element, and say: forbidden squares are $(1, 1), (2, 2), \ldots$, you place a rook on square $(1, 2)$, and thus squares $(2, 2), (3, 2), (4, 2), \ldots$ are now closed, but $(2, 2)$ was already closed before that, so nothing changed.

My question is: can you evaluate "offhand" if it would be hard to solve on a computer? By solving I mean continue the sequence $1, 2, 9, \ldots$ for increasing chessboard size. And secondly: is such a programm really would be easier to write on python than c/c++? To me it seems like an easy thing for a computer to calculate, but what if I'm missing something.

I'm not even asking to solve this problem, but if you want then I don't mind. If you want to do it on a computer than I also would be very glad. But maybe this question is already known or explained in some book? I don't know because I came up with this problem myself, but I don't consider myself an expert in combinatorics, so maybe I just don't know something. It seems obvious that for any $n$ and arbitrary set of cut squares there can't be any algorythm. In any case, thank you a lot.

Add: After posting I realised why it seems easy to caltulate on a machine. In a "worst case scenario" you could just place $n$ rooks on a special board in any way possible and than add $+1$ if no one of them are hitting each other. Of course it would take a huge amount of time, but it should work. For regular board it would be $8\cdot7 = 56$ squares, $C_{56}^8$ seems like impossible number, but you could hugely decrease it by placing only one rook on a line. So it's just $7^8$ positions to check which is still a lot.

RobPratt
  • 45,619
  • 2
    Wouldn't this just be the same as the number of derangements of an $n$-element set? – Daniel Schepler Jul 07 '22 at 22:45
  • 1
    Can rooks "attack" across the holes in the diagonal? – hardmath Jul 07 '22 at 22:56
  • So you're saying that any square with coordinates $(k, k)$ is forbidden? In other words, no rooks may be placed anywhere on the main diagonal? – Robert Shore Jul 07 '22 at 23:00
  • You might be interested in reading about the method of Rook Polynomials – awkward Jul 08 '22 at 13:18
  • 1
    Note that framing this problem in terms of another chess piece is both thematic and lends itself to further generalization. "An $n\times n$ chessboard has a single bishop at (a1). In how many ways can $n$ rooks be added such that no rook is attacked by the bishop or another rook?" Now the bishop can be placed elsewhere, or replaced by a knight or king or queen, or paired with a second bishop, etc. – mjqxxxx Jul 08 '22 at 16:36
  • 1
    @hardmath yes, they can, sorry I forgot to mention that – Petya Balabanov Jul 13 '22 at 03:41

3 Answers3

6

This is only slightly more complicated than the $n$-rooks problem on the full board. Let $T_n$ be the number of ways to place $n$ non-attacking rooks on an $n\times n$ board where one square in each row, each in a different column, is banned (= may not be used for placement, but can still be attacked across). Let $S_n$ be defined the same way, except that only $n-1$ rows contain banned squares. Placing a rook in any row on the $T_n$-board can be done in $n-1$ ways, and when the relevant row and column are removed from the board, what remains is an $S_{n-1}$-board. So $$ T_n = (n-1)S_{n-1}. $$ Placing a rook in the full row on the $S_n$-board, on the other hand, can be done in $1$ way that leaves a $T_{n-1}$-board, and $n-1$ ways that leave an $S_{n-1}$-board. So $$ S_n = T_{n-1} + (n-1)S_{n-1} = T_n + T_{n-1}. $$ Combining these gives the recursion $$ T_{n}=(n-1)S_{n-1}=(n-1)(T_{n-1} + T_{n-2}) $$ for $n\ge 2$, with the starting values $T_0=1$ and $T_1=0$. Iterating this yields the familiar sequence $1,0,1,2,9,44,265,1854,14833,\ldots$, which we recognize (?) as the number of derangements of $n$ elements (A000166 in the OEIS). And this shouldn't be surprising: the legal assignments of column numbers to the rooks in rows $1$ through $n$ are exactly the derangements of $[1,2,\ldots,n]$, because the disallowed permutations are exactly those with a fixed point (i.e., a rook with the same row and column numbers, or a rook on the main diagonal).

mjqxxxx
  • 41,358
3

This is the number of Derangements of $n$ items, $\mathcal{D}_n$. That is, let the row number of the rook on column $k$ be $r(k)$; then $r$ is a derangement of $[1,n]$.

Several methods to compute $\mathcal{D}_n$ are derived in this answer. In that answer, it is shown that for $n\gt0$, $$ \mathcal{D}_n=\left\lfloor\frac{n!}e+\frac12\right\rfloor $$ That is, $\mathcal{D}_n$ is the closest integer to $\frac{n!}e$.

robjohn
  • 345,667
0

Edit: This assume can't put piece on a specific diagonal square not that the whole diagonal is disallowed.

Let $S_n$ be the number of arrangements for rooks on an $n \times n$ chessboard with no hole. We can see via induction that $S_n = n!$. (How? Pick a row, a rook must be placed in that row, there are $n$ choice. Remove the corresponding row and column, use induction hypothesis).

Now we can do something similar here. Let $T_n$ be the number of such arrangements on a chessboard with a hole. Specifically look at the row with the hole. We now have $n-1$ choices and each one we have $(n-1)!$ competitions. So we see that

$$ T_n = (n-1)S_{n-1} = (n-1)(n-1)!$$

This does not match your numbers. $T_2 = 1 \cdot 1! = 1$, $T_3 = 2 \cdot 2! = 4$ and $T_4 = 3 \cdot 3! = 18$.

For the $3 \times 3$ cases let us label the board with coordinates from $1,2,3$ and imagine the $(1,1)$ square is missing.

Rook on $(1,2)$

Then two completions are $(2,1), (3,3)$ and $(3,1), (2,3)$

Rook on $(1,3)$

Then two completions are $(2,1), (2,3)$ and $(3,1), (2,2)$

All 4 of these are distinct.