On the Maximum Number of Non-intersecting Diagonals in an Array

Peter Boyland

Department of Mathematical Sciences

Carnegie Mellon University

Pittsburgh, PA 15213

USA

pboyland@andrew.cmu.edu

Ivan Roth

Department of Mathematics, Statistics and Computer Science Marquette University Milwaukee, WI 53233

USA

ivan.roth@mu.edu

Gabriella Pintér and István Laukó Department of Mathematical Sciences University of Wisconsin-Milwaukee Milwaukee, WI 53211 USA

                            gapinter@uwm.edu
                             iglauko@uwm.edu

Jon E. Schoenfield Huntsville, AL USA

                           jonscho@hiwaay.net

Stephen Wasielewski

Rufus King International School — High School

Milwaukee, WI 53209 USA

       zeebaneighba21@gmail.com

Abstract

We investigate the total number of diagonals that can be placed in the unit squares of a given grid in such a way that no two diagonals have a common point. We develop theoretical and computational results for square and rectangular shaped grids, and extend the problem to three-dimensional arrays. We pose some open questions for further investigation.

1 Introduction

Constrained discrete planar or spatial filling problems are important in applications, and can lead to theoretically and computationally challenging questions. In this paper we consider an aspect of such a filling problem. Integer sequence \underline{A264041} in the OEIS [6] grew out of the following puzzle [1]:

Sixteen unit squares are arranged in a square array. What is the maximum number of diagonals that can be drawn in these unit squares so that no two diagonals share a common point (including endpoints)?

The problem is reminiscent of classical chessboard problems that involve placing the maximum number of certain types of chess pieces (e.g., queens, bishops, rooks or pawns) on the board so that no piece attacks another [2, 5, 4]. The number of possible arrangements containing the maximum number of pieces is often of interest as well. Typically, these kinds of problems can be cast in a graph theoretic setting, and computational techniques, for example, integer programming, can be very useful in obtaining some results.

Our exposition follows the way the investigation of this problem unfolded. After some experimentation one can see that the maximum number of diagonals that can be placed in this particular grid according to the rules is 10. The first question that arises naturally is the case of general n × n square arrays. In Section 2 we study this problem and describe some partial results as well as upper and lower bounds for the maximum number of diagonals that can be placed in square arrays. In Section 3 we extend the question to m × n rectangular arrays, and provide some theoretical and computational results together with some conjectures. In Section 4 we describe our results for the three-dimensional case. We close by posing some open questions for further investigation.

2 Square arrays

For m, n ∈ ℤ^{+}, let D(m, n) denote the maximum number of diagonals that can be placed in the unit squares of an m × n array so that no two diagonals cross or share an endpoint. We will use the notation D(n) for D(n, n). Some experimentation with n = 1, 2, 3, 4 yields D(1) = 1, D(2) = 3, D(3) = 6, D(4) = 10 (Figure 1), which might lead to the conjecture that D(n) = \frac{n(n+1)}{2}. As we consider larger square arrays, however, we can see that the conjecture does not hold for n = 5, since D(5) ≥ 16. However, the arrangement (which we will refer to as the L-arrangement, since it places diagonals in cells that form nested L-shapes) seen in Figure 1 provides a lower bound for D(n) for general n ∈ ℤ^{+}.

Proposition 1. For all n ∈ ℤ^{+}, we have D(n) ≥ \frac{n(n+1)}{2}.

Proof. Note that the L-arrangement by which diagonals are placed in the square array in Figure 1 can always be realized. That is, ‘positive’ (positive slope) diagonals can be drawn in the leftmost column and in the bottom row (forming the outermost L); then a column

(a) D(1) = 1  (b) D(2) = 3  (c) D(3) = 6  (d) D(4) = 10

Figure 1: The first four square arrays.

is skipped and diagonals are placed in the next column until we reach the (n − 2)nd row, where the diagonals are continued to the right (forming the next L). The L-arrangement can also be done for rectangular arrays, and it will be used throughout the paper. The number of diagonals in the L-arrangement in a square array of side n is L(n) = L(n, n) = n + (n − 1) + ⋯ + 1 = \frac{n(n+1)}{2}, as can be seen by summing up the diagonals in the ‘legs’ of the Ls. Thus, L(n) ≤ D(n). (We remark that another way to count the diagonals in this arrangement would be by considering the lattice points that are the endpoints of the diagonals (as described below), but the former method shows the connection to triangular numbers more transparently.)

It turns out that in certain cases, for example, when n is even, the L-arrangement provides not only a lower bound, but an upper bound as well. In particular, when the side of the square array is even, the corresponding triangular number is the answer to our original question.

Theorem 2. D(2n) = L(2n) = n(2n + 1), for all n ∈ ℤ^{+}.

Proof. From Proposition 1 we already know that L(2n) ≤ D(2n), so it suffices to show that D(2n) ≤ n(2n + 1) = L(2n). Consider a 2n × 2n array, and color the top horizontal line of lattice points red, the next one blue, the next one red, and so on, alternating these colors until the last (i.e., the (2n + 1)st) horizontal line of lattice points, which will be red again as shown in Figure 2. Any diagonal that is drawn in this array connects a red lattice point with a blue one. Since there are only n(2n + 1) blue lattice points and there can be at most one diagonal associated with any lattice point, we have D(2n) ≤ n(2n + 1), which proves the claim.

The same argument shows the following result.

Proposition 3. For m ∈ ℤ^{+}, any m × 2 or 2 × m segment of an array contains at most m + 1 diagonals, and D(2, m) = m + 1, for all m ∈ ℤ^{+}.

Theorem 2 provides an answer to our original question for square arrays with an even side, but as we have noted, squares of an odd side length may accommodate more diagonals than provided by the L-arrangement. We first consider a special case, n = 7, and then develop a more general argument.

Figure 2: The coloring argument for even-sided squares.

Proposition 4. D(7) = 29 = L(7) + 1.

Proof. Note that L(7) = 28, so the claim is that the 7 × 7 square array can accommodate one extra diagonal above the L-arrangement. Let us divide the 7 × 6 array that results from omitting the leftmost column of the original square into three 7 × 2 pieces. Proposition 3 implies that D(7, 6) ≤ 3 · 8 = 24, so the maximum number of diagonals that can go into a 7 × 7 array satisfies D(7) ≤ 24 + 7 = 31. Now let us assume that D(7) ≥ 30. Since D(7, 6) = D(6, 7) ≤ 24 this implies that columns 1 and 7 must each contain at least 6 diagonals, and so must rows 1 and 7. Since we also have that D(2, 7) = 8 (Proposition 3 and L-arrangement), we can see that columns 2 and 6, as well as rows 2 and 6, contain at most 2 diagonals each. Now we repeat the argument for the 7 × 5 array that we get if we omit the first two columns of the original array. Since D(7) ≥ 30 by assumption, this implies that D(7, 5) ≥ 22, and then since D(7, 4) ≤ 2 · 8 = 16, we can argue that at least 6 diagonals must fit in column 3 and column 5 of the original grid, and at most 2 diagonals can go in column 4. The same is true for the corresponding rows. Thus, each shaded column and row in Figure 3a contains at most 2 diagonals, or a total of at most 3 · 2 + 3 · 2 = 12 diagonals. Since there are only 16 non-shaded squares, the total number of diagonals that can be placed in the array would be at most 28, which is a contradiction; thus, D(7) < 30. It is possible to place 29 diagonals in the 7 × 7 grid as shown in Figure 3b. Hence, we can conclude that D(7) = 29 = L(7) + 1. Note that a similar argument can be used to establish that D(5) = 16 = L(5) + 1.

(a) Restrictions for n = 7.  (b) A solution with 29 diagonals for n = 7.

Figure 3: The n = 7 case.

Since we can see that the number of diagonals can be larger than what is allowed by the Larrangement in squares of odd sides, a natural question arises about how large this difference can be. Let us introduce the notation K(n, m) = D(n, m) − L(n, m), where K(n, m) is the number of extra diagonals accommodated by the array with dimensions n and m above the L-arrangement. The abbreviated notation K(n) is used for K(n, n). First we will show that K is not bounded.

Proposition 5. D(6m − 1) ≥ L(6m − 1) + m, that is, K(6m − 1) ≥ m. Thus, the number of extra diagonals above the L-arrangement is not bounded.

Proof. We prove the statement by an appropriate construction. Consider a (6m−1)×(6m−1) square, and put diagonals in its center (2m + 1) × (2m + 1) square in a checkerboard pattern starting with m positive diagonals in its first row, and (m + 1) negative diagonals in its second one, alternating the number and orientation of the diagonals from row to row. See Figure 4a for the square of side 17.

(a) Construction for n = 17.  (b) Construction for n = 13.

Figure 4: The n = 17 and n = 13 cases.

Now consider the kth diagonal from the left (k = 1, 2, …, m) touching the top edge of the (2m+1)×(2m+1) center square. We place a positive diagonal in each of the 2k −1 unit squares directly above this diagonal, then turn 90 degrees counterclockwise, and continue placing positive diagonals until we reach the boundary of the (6m − 1) × (6m − 1) array. Next, we turn the entire (6m−1)×(6m−1) array 90 degrees clockwise (or counterclockwise) and carry out the same procedure of placing diagonals using the new top edge. After two more repetitions, the construction is finished, as illustrated in Figure 4a.

The construction results in the use of each of the 6m · 6m lattice points of the (6m − 1) × (6m − 1) array as an endpoint of a diagonal, except for 4m lattice points along the sides of the array (marked by small yellow squares in Figure 4a). So the total number of diagonals placed is \frac{6m·6m−4m}{2} = 3m(6m − 1) + m = L(6m − 1) + m, as claimed.

Note that the construction above provides a lower bound for squares of sides (6m + 1) and (6m + 3) as well, since a full L-shape, i.e., (6m + 1) + 6m diagonals, can be added in the width-2 ‘skirt’ around the left and the bottom sides of a (6m−1)×(6m−1) square array. (Do this twice to fill a (6m + 3) × (6m + 3) array.) For a square of side (6m + 1) the construction results in 3m(6m−1)+m+(6m+1)+6m = (3m+1)(6m+1)+m = L(6m+1)+m diagonals, i.e., D(6m + 1) ≥ L(6m + 1) + m. A similar calculation yields D(6m + 3) ≥ L(6m + 3) + m.

Upper bounds for D in odd-sided squares can be established by generalizing the argument in Proposition 4 as follows.

Proposition 6. D(2n + 1) < L(2n + 1) + M, where M = ⌈\frac{n(n+1)}{2n+1}⌉ = ⌈\frac{n+1}{2}⌉ , n ∈ ℤ^{+}.

Proof. We proceed by contradiction, and assume that D(2n + 1) ≥ L(2n + 1) + M. Since there are at most n(2n + 2) diagonals in the (2n + 1) × 2n array that we get by omitting the leftmost column, it follows that there must be at least L(2n+1)+M −n(2n+2) = n+1+M diagonals in the first and last columns each (and in the first and last rows each). However, since there cannot be more than (2n + 2) diagonals total in the first two columns, there must be at most n + 1 − M diagonals in the second column, and the 2nth column, as well as in the second and 2nth rows. The argument can be continued inside similarly as in the proof of Proposition 4 to obtain that each even-numbered column and row contains at most n + 1 − M diagonals. This results in at most 2n(n + 1 − M) diagonals in these rows and columns, and (n + 1)^{2} open (non-shaded) squares that may admit diagonals; that is, a total of at most 2n(n + 1 − M) + (n + 1)^{2} diagonals can be placed in the array. However, this is less than what we claim the array contains, and results in a contradiction, since 2n(n+1−M)+(n+1)^{2} < L(2n+1)+M = (n+1)(2n+1)+M by the fact that M > \frac{n(n+1)}{2n+1}. Note that M ≠ \frac{n(n+1)}{2n+1}, since \frac{n(n+1)}{2n+1} cannot be an integer if n is a positive integer. In fact,

we can see that ⌈\frac{n(n+1)}{2n+1}⌉ = ⌈\frac{n+1}{2}⌉ since \frac{n}{2} < \frac{n(n+1)}{2n+1} < \frac{n+1}{2}, and this completes the proof of the proposition.

We remark that the construction in Proposition 5 together with the upper bound above can establish that D(11) = 68. While the bound above is not sharp enough to determine D for other odd values greater than 7, we can combine it with our construction to determine that 1 ≤ K(9) ≤ 2, 2 ≤ K(13) ≤ 3, 2 ≤ K(15) ≤ 3, and in general, ⌊\frac{n+1}{3}⌋ ≤ K(2n + 1) ≤ ⌊\frac{n}{2}⌋ .

The following bound is also useful.

Proposition 7. K(2n + 1) ≤ K(2n − 1) + 1.

Proof. In general, we have that D(2n + 1) ≤ D(2n − 1) + D(2n + 1, 2) + D(2, 2n − 1). That is,

L(2n + 1) + K(2n + 1) ≤ L(2n − 1) + K(2n − 1) + 2n + 2 + 2n
(n + 1)(2n + 1) + K(2n + 1) ≤ n(2n − 1) + K(2n − 1) + 4n + 2
K(2n + 1) ≤ K(2n − 1) + 1.

3 Rectangular arrays

The diagonal placement problem can naturally be extended to rectangular arrays. In fact, we have already shown that D(2, n) = n + 1 for all n ∈ ℤ^{+}. However, before considering the general case, let us examine what happens to the L-arrangement in rectangular arrays.

Proposition 8. The number of diagonals in the L-arrangement in rectangular arrays is given by L(2m + 1, 2n + 1) = L(2n + 1, 2m + 1) = (2m + 1)(n + 1) and L(2m, 2n) = L(2n, 2m) = n(2m + 1) for all n ≤ m, n, m ∈ ℤ^{+}, while L(2m + 1, 2n) = L(2n, 2m + 1) = 2n(m + 1) for all n, m ∈ ℤ^{+}. Furthermore, when both dimensions of the rectangle are odd, L(m, n) = L(n, m) = max(m, n)(min(m, n) + 1)/2.

Proof. We can see that L(m, n) can be expressed recursively, since the number of diagonals in the L-arrangement in the m × n rectangle is equal to the number of diagonals in the Larrangement in the (m−2)×(n−2) rectangle plus the number of diagonals in the outermost L, that is, the number of cells along the left and bottom edges of the rectangle. Thus,

L(m, n) = m + n − 1 + L(m − 2, n − 2), for m, n ≥ 2

and

L(m, 1) = m, L(1, n) = n, L(m, 0) = 0, L(0, n) = 0.

For the case when both dimensions of the rectangle are odd, we have

L(2m + 1, 2n + 1) = \begin{cases}(2m + 1) + (2n + 1) − 1 + L(2m − 1, 2n − 1), & for m, n > 0; \\ 2m + 1, & for n = 0; \\ 2n + 1, & for m = 0. \end{cases}

Now we can expand the above equation iteratively, assuming that m ≥ n, as follows:

L(2m + 1, 2n + 1) = (2m + 1) + (2n + 1) − 1 + L(2m − 1, 2n − 1)
= (2m + 2n + 1) + ((2m − 1) + (2n − 1) − 1) + L(2m − 3, 2n − 3)
⋮
= (2m + 2n + 1) + (2m + 2n − 3) + ⋯ + L(2m − 2n + 1, 1)
= (2m + 2n + 1) + (2m + 2n − 3) + ⋯ + (2m − 2n + 1)
= (2m + 1)(n + 1).

This proves the statement for the case when both dimensions of the rectangle are odd. Moreover, it is easy to see that

L(2m + 1, 2n + 1) = (2m + 1)(n + 1) = max(2m + 1, 2n + 1)(min(2m + 1, 2n + 1) + 1)/2,

as claimed. The other cases, that is, when both sides of the rectangle are even, or when one is even and the other is odd, can be proved similarly based on the recursion for L(m, n).

Now, Theorem 2 can easily be generalized to cover all rectangular arrays with at least one even side.

Theorem 9. D(2n, 2m+1) = L(2n, 2m+1) = n(2m+2) for all n, m ∈ ℤ^{+} and D(2n, 2m) = L(2n, 2m) = n(2m + 1) for all n ≤ m, n, m ∈ ℤ^{+}.

Proof. First consider a 2n × (2m + 1) array. Color the lattice points on the top horizontal gridline red. Make the next line of lattice points blue and continue alternating the color of the lattice points line by line, until the last horizontal line, where the lattice points are red again since the array has an even number of rows. Thus we obtain n + 1 red and n blue lines of lattice points. Since every diagonal connects a red and a blue lattice point, it follows that D(2n, 2m + 1) ≤ n(2m + 2). The L-arrangement in the array provides exactly (m+1)·2n = n(2m+2) diagonals, as can be seen by adding the number of diagonals in pairs of rows. Thus we can conclude that D(2n, 2m + 1) = n(2m + 2). The case when both sides are even is very similar. Here we have D(2n, 2m) ≤ n(2m + 1) and D(2n, 2m) ≤ m(2n + 1) by applying the coloring argument along both dimensions. Since n ≤ m by assumption, D(2n, 2m) ≤ n(2m + 1) is the sharper bound, and the L-arrangement makes the placement of this many diagonals in the array possible. Thus D(2n, 2m) = n(2m + 1) when n ≤ m.

As was the case with square arrays, we can see that only rectangles with both dimensions odd have the potential to accommodate more diagonals than what the L-arrangement would provide, and these are the interesting cases to investigate. Some experimentation suggests that D(7, 5) = L(7, 5) = 21, but D(9, 7) = L(9, 7) + 1 = 37, while D(11, 7) = L(11, 7). That is, we can no longer do better than the L-arrangement once the array becomes sufficiently oblong. To examine this and the square case systematically, we turned to computational algorithms that implemented an exhaustive search to find D(n, m) in general, together with the number of solutions containing the maximum number of diagonals for a given array size.

3.1 Search algorithms

As described by Israel in a comment for sequence \underline{A264041} in the OEIS [6], the diagonal problem can be cast as that of finding a maximum independent set in an appropriate graph G. Let the vertices of G correspond to the diagonals in an n × m array and be indexed by the triple (x, y, z), where 1 ≤ x ≤ n, 1 ≤ y ≤ m, and z = 1, 2, with z = 1 corresponding to ‘positive’ diagonals (positive slope) and z = 2 corresponding to ‘negative’ diagonals (negative slope). Two vertices are connected by an edge in G whenever the two corresponding diagonals have a common point. Thus (x, y, 1) is connected to (x, y, 2) for every 1 ≤ x ≤ n, 1 ≤ y ≤ m. Additionally, (x, y, 1) is connected to (x+1, y+1, 1), (x, y, 2) to (x+1, y−1, 2), and (x, y, z) is connected to both (x+1, y, 3−z) and (x, y+1, 3−z). The search for a maximum independent set in G was performed using integer programming by means of an IBM ILOG CPLEX [3] routine in MATLAB. The code by Israel that treats square arrays is available through a link under sequence \underline{A264041} in the OEIS [6]. We adapted the code to cover rectangular arrays, and ran it until computer memory and/or run time limited the size of arrays that could be solved this way as described under \underline{A260690} in the OEIS [6]. Our computational results for arrays of odd dimensions are summarized in Figure 5. One can readily observe how the more oblong arrays lose the potential of accommodating extra diagonals above the L-arrangement.

Figure 5: Computed values of D(n, m). Values in cells without all four borders and with numbers in small font are conjectures; other values are verified maxima for the given dimensions. Colors indicate the number of extra diagonals that the array can accommodate above the L-arrangement.

We remark that a more direct search algorithm has also been developed by one of the authors (Schoenfield) that fills the array row by row, and counts the number of optimal solutions for each pair (n, m) where both n and m are odd. Table 1 gives the number of arrangements that have the maximum number of diagonals for an n × m array.

1 3 5  7  9  11  13  15
1 2 2 2  2  2  2  2  2
3 2 28 30  34  38  42  46  50
5 2 30 2  2482  3266  4210  5282  6482
7 2 34 2482 480  32  1634780 2555996  3832876
9 2 38 3266  32  433284 85328  7568  256
11 2 42 4210 1634780 85328  256  619672582 133534888
13 2 46 5282 2555996 7568 619672582 14454384  28224
15 2 50 6482 3832876 256 133534888 28224 1401615406696

Table 1: Number of optimal solutions for rectangular arrays. Arrangements that can be rotated and/or reflected into each other are counted as distinct.

Figure 6: Some computed solutions for the 11 × 11 array. Instead of showing each diagonal, cells that have a positive diagonal are colored red, while cells with a negative diagonal are blue.

Some of the 256 solutions for the 11×11 array are depicted in Figure 6. While visualizing the computed arrangements, one can observe that some of them seem to be forming ‘braids’ through the array. This is even more noticeable if the cells containing positive diagonals are painted in one color, and negative diagonals in another color. In fact, these braids can provide a convenient way of constructing solutions with K(n, m) > 0 for certain types of rectangular arrays.

Figure 7: A braided solution for a 21 × 11 array. Arrows show the entry and exit points of the red (positive diagonals) and blue (negative diagonals) threads.

3.2 Braided solutions

Let us consider the 21 × 11 braid pattern in Figure 7. It has L(21, 11) + 1 = 126 + 1 = 127 diagonals, that is, it admits the maximal one extra diagonal above the L-arrangement since we know that D(21, 11) = 127 (see Figure 5). It is achieved in the following way. In each pair of rows there can be at most 12 diagonals, and here we have 7 diagonals in each odd row, and 5 in each even one. Thus, the last row, which is an odd row, will contain 7 diagonals, which is one more than the average of 6 per row, which comes from the Larrangement: L(21, 11) = 6 · 21 (which is the same total number of diagonals as would be obtained from simply having 6 vertical threads, one filling each odd-numbered column). The extra diagonal in each odd row is created by ‘sliding’ the threads horizontally. We can devise a general strategy of constructing braid patterns along these lines, and we can examine how many extra diagonals they admit.

Let w, h be both odd, with w denoting the number of columns, and h the number of rows in a particular array. Suppose we attempt to construct a braided solution with K extra diagonals (where K ≥ 1 is a given value) in which the number of diagonals in every odd-numbered row is \frac{w+1}{2} + K, and the number of diagonals in every even-numbered row is \frac{w+1}{2} −K. We do not place a diagonal in any cell that is the intersection of an even-numbered row and an even-numbered column. The diagonals lie along \frac{w+1}{2} − K braided threads, with each thread occupying exactly one cell on each even-numbered row. However, collectively, the threads occupy an additional 2K cells on each odd-numbered row. If we envision a ‘zeroth row’ just above the top of the grid, there are ‘entry points’ (at odd-numbered columns) for each of the red (positive diagonals) threads starting from the left, and for the blue (negative diagonals) threads starting from the right, with K entry points in between that are left empty. Constructing the pattern from the top row downward, each thread’s contribution to these 2K additional cells is accomplished by ‘sliding’ to the left (for blue threads) or right (for red threads) by an even number of columns, sometimes jumping across one or more threads of the opposite color.

Consider only the C = \frac{w+1}{2} odd columns, and start from the left with R entry points for the R red threads, followed by K empty entry points, followed by B entry points for the B blue threads: R + K + B = C. No thread crosses any thread of the same color, but since the blue threads will end up on the left and the red threads on the right, every thread crosses every thread of the opposite color. Below the bottom row, picture an (h + 1)st row for ‘exit points’. There will be B exit points for the blue threads, K empty exit points, and R exit points for the red threads. Between the entry row (0) and the exit row (h + 1), each red thread will have been slid to the right by at most K + B odd columns, and each blue thread will have been slid to the left by at most K + R odd columns. Each ‘slide’ covers an additional 2J diagonals where J is the length of the slide, in odd columns. However, each crossing of threads deducts two diagonals, i.e., it does not gain one for the color being slid, and it does remove one of the opposite color.

The maximum number of ‘additional’ diagonals, that is, ‘additional’ beyond the (R+B)·h diagonals that would be drawn if each thread were simply drawn as a single, vertical column, is 2R·(K +B)+2B ·(K +R)−2RB, in which the terms 2R·(K +B), 2B ·(K +R) and −2RB account for the additional diagonals from sliding the reds to the right, those from sliding the blues to the left, and the diagonals lost because of the thread crossings, respectively. To maintain the alternating number of diagonals per row as \frac{w+1}{2} + K on each odd-numbered row and \frac{w+1}{2} − K on each even-numbered row, we must get 2K extra diagonals on each odd-numbered row. This can be maintained for a maximum of

h_{odd,max} = ⌊\frac{2R · (K + B) + 2B · (K + R) − 2RB}{2K} ⌋ = R + B + ⌊\frac{RB}{K} ⌋

odd-numbered rows, which potentially allows construction of a pattern whose height is at most h_{max} = 2 · h_{odd,max} − 1 rows. The quantity R + B + ⌊\frac{RB}{K} ⌋ is maximized if R and B are as nearly equal as possible (since their sum is fixed). Thus we can arbitrarily set B = ⌊\frac{C−K}{2} ⌋ and then let R = C − K − B. The resulting h_{max} × w array would have K extra diagonals above L(h_{max}, w), that is, T (h_{max}, w) = L(h_{max}, w) + K, where T (h, w) denotes the number of diagonals that can be placed in an h × w array using the braid construction described above. Thus, D(h_{max}, w) ≥ T (h_{max}, w), which provides a sharper lower bound than the one from the L-arrangement.

In our former example with w = 11, the argument would go the following way. The question is what the largest h ≥ w is such that K(h, w) = 1. Then C = 6 = R+B +1, so we can let R = 3, B = 2, i.e., have three red and two blue threads. The construction described above can potentially be maintained for h_{odd,max} = 5 + 6 = 11 odd rows, or h_{max} = 21 rows, so it would result in a 21 × 11 array with 1 extra diagonal above the L-arrangement. Thus T (21, 11) = 127, which turns out to be the same as D(21, 11). Figure 7 shows the construction, so we can see that it is feasible in this case. Note that this result also provides the lower bound D(h, 11) ≥ T (h, 11) ≥ L(h, 11) + 1 for h_{max} = 21 ≥ h ≥ 11, h odd. Now take K = 2. In this case, R + B = 4, so let R = B = 2. We can see that h_{max} = 11, which could lead to any of the arrangements in the last column of Figure 6. If one takes K = 3, then R + B = 3, and h_{max} = 5, which is smaller than w = 11. So a braided solution with 3 extra diagonals is not possible in arrays with 11 columns. While this argument is very appealing, and the construction seems straightforward as shown in Figure 7, one might run into difficulties, especially when there are many empty entry/exit points. Thus it is important to investigate whether this construction could actually be carried out for all relevant values of R, B and K.

3.3 Feasibility of the braid construction

Our first observation concerns a potential reduction in the number of red or blue threads.

Proposition 10. Suppose w and h are odd, w ≤ h. Let R + B + K = \frac{w+1}{2}, R ≥ K, and assume that the goal is to construct a braided solution for (K, R, B). This problem can be reduced to that of finding a braided solution for (K, R − K, B). Similarly, any problem (K, R, B) with B ≥ K can be reduced to (K, R, B − K).

Proof. If R ≥ K, the problem of finding a braided solution for (K, R, B) can be simply reduced to the problem of finding a braided solution for (K, R − K, B) by making the following moves (i.e., horizontal slides of the threads) on successive odd rows (beginning with row 1):

1. For each of the first B moves, move the leftmost movable blue thread as far as possible to the left.

2. For each of the next K moves, move the rightmost movable red thread as far as possible to the right (jumping over all the blue threads).

After these moves, K of the red threads are in their final positions occupying the K rightmost odd columns of the array, so the problem is reduced to that of finding a set of moves that will successfully solve the remaining problem that has only R − K red threads at the far left, followed by K empty columns, followed by the B blue threads on the right. The reduction of the number of blue threads can be done similarly, with red and blue as well as left and right interchanged.

We remark that the reduction steps described above can be applied several times, one after another. Thus, we can state the following corollary.

Corollary 11. The problem of finding a braided solution for (K, R, B) reduces to that of (K, R′, B′) = (K, R mod K, B mod K).

In the following, let R′ = R mod K and B′ = B mod K. We note that braided solutions for (K, 0, B′), or for (K, R′, 0), are very easy to construct. In each case the blue (or red) threads can simply slide K odd columns one after the other to the left (or to the right) in consecutive odd rows until they reach their end positions. A rectangular array with w = (6n + 1) columns and K = n leads to finding a braided solution for (n, n + 1, n), which reduces to (n, 1, 0), while arrays with w = (6n+3) columns and K = n lead to (n, n+1, n+1), which reduces to (n, 1, 1). In general, any (K, R′, B′) problem with B′ = 1 can be solved in the following way.

1. For the first move, move the blue thread as far as possible to the left.

2. For each of the next R′ moves, move the rightmost movable red thread as far as possible to the right (jumping over the blue thread).

Of course, the steps above work with red and blue (and left and right) interchanged as well, reflecting the symmetry of the problem.

Example 12. Consider w = 29 and suppose we are looking for arrays with K = 4 extra diagonals. According to the formulas in Section 3.2 for h_{odd,max} and h_{max}, the largest 29column array for which a braided solution can accommodate four extra diagonals has h_{max} = 2(11 + ⌊\frac{30}{4}⌋) − 1 = 35 rows. Thus we look for a braided solution for (4, 6, 5), which we can reduce to (4, 2, 5), then to (4, 2, 1). The relevant steps are illustrated in Figure 8.

It is also possible to devise a construction pattern for the general case (K, R′, 2), or (K, 2, B′), but it may be much more complicated for some values of K and R′ or of K and B′. We have tested a general algorithm that, while considerably more complex than the ones described above, successfully generates a braided solution with h_{max} = 2(R′+B′+⌊\frac{R′B′}{K} ⌋)−1 rows for all cases where R′ = ⌈\frac{R′+B′}{2} ⌉ and R′ < K ≤ 1000. However, even the partial results here can provide more insight into the structure of Figure 5. In particular, we note that the maximum number of diagonals in an array with odd dimensions agrees with what the braid construction would provide for all computed values of D(h, w). Thus, we conjecture that T (h, w) = D(h, w) for h, w odd. Moreover, we claim the following.

Figure 8: A braided solution for a 35 × 29 array. The first reduction yields the reduced solution in the yellow box, while the second yields the one in the black box.

Proposition 13. Suppose w and h are odd. The maximum number of diagonals that can be placed in the h × w array using a braided solution is T (h, w) = L(h, w) + K, where

K = ⌊\frac{t − 2s + 2\sqrt{t^{2} − st + s^{2}}}{3} ⌋ ,

with s = \frac{max (h,w)+1}{2} and t = \frac{min (h,w)+1}{2}.

Proof. Assume that h ≥ w, so s = \frac{max(h,w)+1}{2} = \frac{h+1}{2} and t = \frac{min(h,w)+1}{2} = \frac{w+1}{2}. From the braided solution we have that h_{odd,max} = max (R + B + ⌊\frac{RB}{K} ⌋), where R + B + K = t. Thus for fixed w and K

h_{max}(w, K) = 2h_{odd,max} − 1 = 2 (t − K + ⌊\frac{(\frac{t−K}{2} )2}{K} ⌋) − 1.

This means that if the h × w array has K extra diagonals, then

w ≤ h ≤ 2 (t − K + ⌊\frac{(\frac{t−K}{2} )2}{K} ⌋) − 1,

and we can solve this inequality for K. We obtain

\frac{h + 1}{2} ≤ t − K + ⌊\frac{(\frac{t−K}{2} )2}{K} ⌋

\frac{h + 1}{2} ≤ t − K + ⌊\frac{t^{2} − 2tK + K^{2}}{K} · \frac{1}{4}⌋

\frac{h + 1}{2} ≤ ⌊\frac{4tK − 4K^{2} + t^{2} − 2tK + K^{2}}{4K} ⌋

\frac{h + 1}{2} ≤ ⌊\frac{t^{2} + 2tK − 3K^{2}}{4K} ⌋ .

Since h is an odd integer, this is equivalent to

s = \frac{h + 1}{2} ≤ \frac{t^{2} + 2tK − 3K^{2}}{4K}
4sK ≤ t^{2} + 2tK − 3K^{2}
0 ≤ −3K^{2} + K(2t − 4s) + t^{2}.

If we solve the quadratic equation −3K^{2} + K(2t − 4s) + t^{2} = 0 for K, then we get

K_{1,2} = \frac{4s − 2t ± \sqrt{(2t − 4s)^{2} − 4 · (−3) · t^{2}}}{−6} = \frac{t − 2s ∓ 2\sqrt{t^{2} − st + s^{2}}}{3} .

The solution of the quadratic inequality in turn is

0 ≤ K ≤ \frac{t − 2s + 2\sqrt{t^{2} − st + s^{2}}}{3} ,

since K ≥ 0. Thus the h × w array can accommodate at least K extra diagonals by the braid construction whenever K satisfies the inequality above. Moreover, the largest such K, i.e.,

K = ⌊\frac{t − 2s + 2\sqrt{t^{2} − st + s^{2}}}{3} ⌋ ,

is the one that provides T (h, w) = L(h, w) + K.

4 Three-dimensional arrays

The original problem can be naturally generalized to three-dimensional arrays. Instead of diagonals in unit squares, consider the space diagonals in the unit cubes that make up the array, and require that no two of the space diagonals placed in the unit cubes of the array cross or share an endpoint. While the straightforward generalization of the coloring argument to parallel planes of lattice points fails, it can be modified to provide a very useful upper bound.

Proposition 14. The maximum number of space diagonals in a 2n × 2m × 2k, n ≤ m ≤ k array is

D(2n, 2m, 2k) ≤ \begin{cases}4nmk + nm + nk + mk, & if n(m + 1) ≥ (m − n)k; \\ 4nmk + n(2m + 2k + 1), & otherwise. \end{cases}

Proof. Let us label the lattice points in the array with 0s and 1s alternating in each direction, x, y, z, starting with 0. That is, each lattice point will be assigned a triple (a, b, c) = (x mod 2, y mod 2, z mod 2). The crucial observation is that each space diagonal connects a lattice point labeled (a, b, c) with one labeled (1−a, 1−b, 1−c). Table 2 lists the number of different types of lattice points in the array.

lattice point  number  lattice point type number
type  of points  connected to  of points
(0, 0, 0)  (n + 1)(m + 1)(k + 1)  (1, 1, 1)  nmk
(0, 0, 1)  (n + 1)(m + 1)k  (1, 1, 0)  nm(k + 1)
(0, 1, 0)  (n + 1)m(k + 1)  (1, 0, 1)  n(m + 1)k
(1, 0, 0)  n(m + 1)(k + 1)  (0, 1, 1)  (n + 1)mk

Table 2: The number of different types of lattice points in a 2n × 2m × 2k, n ≤ m ≤ k array.

For example, we can see that there can be at most nmk space diagonals that connect lattice points of types (0, 0, 0) and (1, 1, 1). As we continue this way, and take the minimum number of diagonals in each row of the table, we arrive at the upper bound

D(2n, 2m, 2k) ≤  min ((n + 1)(m + 1)(k + 1), nmk)
+ min ((n + 1)(m + 1)k, nm(k + 1))
+ min ((n + 1)m(k + 1), n(m + 1)k)
+ min (n(m + 1)(k + 1), (n + 1)mk)
=  nmk + nm(k + 1) + n(m + 1)k
+ min (n(m + 1)(k + 1), (n + 1)mk),

which implies the claim.

One of the first interesting three-dimensional arrays is the 2 × 2 × 2 cube. It is not necessarily easy to see directly that there cannot be 8 non-intersecting space diagonals in this array, but we can use Proposition 14 to establish that D(2, 2, 2) ≤ 7. However, 7 diagonals can be placed in this array, so D(2, 2, 2) = 7. Figure 9 illustrates one way of placing 7 diagonals in the array. From the bottom (0th) level, four space diagonals are drawn upward, each in the same direction. Then from level 1, three more diagonals, also extending upward, can fit in an L-shape. In fact, it turns out that the upper bound above and the type of construction here combine to determine D for all even-sided cubes, and for tall rectangular prisms with a square base (tall square columns) with all sides even.

Figure 9: Seven space diagonals in a 2 × 2 × 2 cube. Circles denote the lower endpoint of a diagonal at level i, while their upper endpoint at level i + 1 is marked by an x.

Proposition 15. For a 2n × 2n × 2k array with k ≥ n, D(2n, 2n, 2k) = 4n^{2}k + n^{2} + 2nk.

Proof. First, by Proposition 14 we have that D(2n, 2n, 2k) ≤ 4n^{2}k + n^{2} + 2nk. Next, we demonstrate a general construction that places exactly 4n^{2}k+n^{2}+2nk space diagonals in the 2n×2n×2k array by expanding on the example above. At the bottom of the column, level 0, we can place (2n)^{2} space diagonals, all going the same way. This will leave all lattice points along two intersecting sides of the next level in the prism free (i.e., no diagonals connect to them from below). Thus, space diagonals originating at these points can be placed in level 1, again in the same orientation as those in level 0. This results in 4n − 1 diagonals in an L-shape. In level 2, not only can we again place the same type of diagonals in the L-shape as one level below, but we can start diagonals from (2n − 2)^{2} lattice points ‘inside’ the L-shape as well. In level 3, we can repeat the large L, but not the square inside, rather, just the L-shaped boundary of the square nesting into the larger L. As we proceed upwards, the levels with nested Ls and a square alternate with just nested Ls (but one more than before) until there is no more room for more L-shapes in level 2n. From that point on, each level can repeat the full nested-L pattern.

Figure 10: 44 diagonals in a 4 × 4 × 4 cube.

If we sum up the number of diagonals in pairs of levels from the bottom up, we obtain

[4n^{2} + (4n − 1)] + [(4n − 1 + (2n − 2)^{2}) + (4n − 1 + 4n − 5)]
+[(4n − 1 + 4n − 5 + (2n − 4)^{2}) + (4n − 1 + 4n − 5 + 4n − 9)]
+ ⋯ + (k − n)[2n(2n + 1)]
= [4n^{2} + (4n − 1)] + [4n^{2} + (4n − 3)] + [4n^{2} + (4n − 5)] + ⋯
+[4n^{2} + (4n − (2n − 1))] + (k − n)[2n(2n + 1)]
= 4n^{3} + 3n^{2} + (k − n)[2n(2n + 1)]
= 4n^{2}k + n^{2} + 2nk.

This arrangement can also be thought of as a collection of nested shells with one horizontal and two vertical adjacent sides.

We remark that this construction can be considered as a type of generalization of the L-arrangement from the two-dimensional problem, and we just showed that it places the maximum possible number of diagonals in tall even-sided prisms with a square base. The arrangement itself does not depend on the parity of the sides of the array. We will refer to this construction as the ‘nested-shell arrangement’ below, and denote the number of diagonals it places into an n × m × k array by S(n, m, k).

Proposition 16. The number of diagonals in the nested-shell arrangement described above is given by

S(n, m, k) = \begin{cases}\frac{1}{4}n(2mk + 2m + 2k − n), & for n even; \\ \frac{1}{4}(n + 1)(2mk + n − 1), & for n odd. \end{cases}

where 0 ≤ n ≤ m ≤ k.

Proof. The proof is very similar to the one we had for the L-arrangement in the twodimensional case. First, we note that S(0, m, k) = 0 for all m, k ≥ 0, and S(1, m, k) = mk, for all m, k ≥ 1, so the formulae work for n = 0 and n = 1. Next, we can see from the construction of the nested shells that the outermost shell contains nm+nk +mk −n−m−k +1 diagonals. Thus S satisfies the following recursion for 2 ≤ n ≤ m ≤ k:

S(n, m, k) = nm + nk + mk − n − m − k + 1 + S(n − 2, m − 2, k − 2).

Now, if we assume that n is even and iteratively expand the terms using the recursion above, we obtain

S(n, m, k) = nm + nk + mk − n − m − k + 1 + S(n − 2, m − 2, k − 2)
= nm + nk + mk − n − m − k + 1
+(n − 2)(m − 2) + (n − 2)(k − 2) + (m − 2)(k − 2)
−(n − 2) − (m − 2) − (k − 2) + 1 + S(n − 4, m − 4, k − 4)
⋮
= nm + nk + mk − n − m − k + 1 + ⋯
+(n − (n − 2))(m − (n − 2)) + (n − (n − 2))(k − (n − 2))
+(m − (n − 2))(k − (n − 2))
−(n − (n − 2)) − (m − (n − 2)) − (k − (n − 2)) + 1
+S(0, m − n, k − n)
= \frac{1}{4}n(2mk + 2m + 2k − n),

where the last equality can be arrived at by collecting like terms and using summation formulas (or can be conveniently computed by Mathematica). The expression for S in the case when n is odd can be obtained in a similar way.

Thus, in general three-dimensional arrays we can obtain a lower bound for the maximum number of diagonals, that is, D(n, m, k) ≥ S(n, m, k). It is natural to use the nested-shell arrangement for general even-sided prisms, and investigate whether it provides an optimal solution as it did for tall even-sided prisms with a square base. To be able to do this, we extended the computer program to treat general three-dimensional arrays. The idea for the code is the same as before: the diagonal placement problem is converted to that of finding a maximum independent set in a graph whose vertices represent the space diagonals of the unit cubes in the array, and edges are drawn between those vertices whose corresponding diagonals have a common point. The code finds the maximum number of diagonals that can be placed in the array and depicts an arrangement of these diagonals as well. The nestedshell arrangement places 120 diagonals in the 4 × 6 × 8 array, while our code constructs a solution with a maximum of 122 diagonals. Hence, the nested-shell arrangement as described above does not provide an optimal solution in general, even in the case when all sides are even. Some experimentation with the computer code also suggests that D(n, m, k) is strictly larger than S(n, m, k) for 2 ≤ n ≤ m ≤ k unless n = m and n and k are even (i.e., we have a tall even-sided prism with a square base). Thus, the nested-shell arrangement does not behave as the L-arrangement did in two dimensions, and D(n, m, k) does not seem to reduce to S(n, m, k) as the prisms get more and more elongated. However, we noticed that in all computed cases the maximum number of diagonals in even-sided arrays agreed with the upper bound in Proposition 14. Thus we strongly suspect that there is a general construction that achieves this upper bound when applied to any even-sided 3-D array.

4.1 Two-layer arrays

We continue with a somewhat trivial upper bound for D, which can nevertheless lead to a nice general result. If we consider any level of lattice points, with length s and width v, then we can easily see that there cannot be more than (s + 1) · (v + 1) space diagonals that connect to these lattice points either by their lower or upper endpoint. So for example, in a 6 × 6 × 2 array, there are three levels of lattice points, and the middle one has 49 potential endpoints for diagonals that connect this level either to the one above or to the one below. This shows that D(6, 6, 2) ≤ 49. Note that the array itself is made up of 72 unit cubes, so this is a meaningful bound. Now, the crucial observation is that all lattice points in this middle level can be occupied except in a few cases. Indeed, we have the following result.

Proposition 17. In an n×m×2 two-layer array with 3 ≤ n ≤ m, D(n, m, 2) = (n+1)(m+1) unless n = m = 4.

Proof. We will argue that each of the (n+1)(m+1) lattice points of the middle level can serve as an endpoint of a diagonal in a valid arrangement. Let us start by placing diagonals going downward from the middle level originating at each of the lattice points along the boundary of the middle level except for the four corners, as depicted in green in the left panels of Figures 11 and 12. Next, put diagonals originating in the four corners going upward (shown in purple in the right panels of Figures 11 and 12). This takes care of the lattice points at the boundary of the middle level. Now consider the lattice points that are in the interior of the middle level. They form a rectangle as well, and we can place an upward diagonal originating at each of the non-corner lattice points on the boundary of this rectangle in a direction that is 45 degrees clockwise from a normal vector pointing outward from that edge of the rectangle. For lattice points at the corners of this inner rectangle, we use the following rule: the direction of the upward diagonal originating at the NE corner of the rectangle is SE, the direction of the diagonal at the SE corner is SW, and the direction for the diagonals at the SW and NW corners is NW and NE, respectively. We can continue inward in this manner, placing upward diagonals at the lattice points on the boundary of each successive rectangle. If n and m are both odd, the construction can be completed this way. If n ≤ m and n is even, then in the last step we arrive at a ‘degenerate rectangle’, that is, a single lattice point at the center if n = m, or a line of m − n + 1 lattice points otherwise. If n = m (with n even), there is an available direction for an upward diagonal originating at the center point (unless n = m = 4). Similarly, if n < m with n even, the endpoints of the line of lattice points in the last step may have some directions blocked (for example, in the 4 × 5 or 4 × 6 cases), but there are enough directions available so that upward diagonals can be placed at each endpoint. Figures 11 and 12 illustrate the constructions described above.

We remark that D(4, 4, 2) = 24, and a solution with 24 diagonals can be obtained using the construction above for the n = m (with n even) case, but with no diagonal originating at the center point.

Figure 11: Middle level of a 5 × 5 × 2 array that contains a total of 36 diagonals. The downward diagonals are depicted in green on the left, while upward diagonals are shown in purple on the right. A small circle denotes the lattice point at which each diagonal originates.

Figure 12: Middle level of a 4 × 6 × 2 array that contains a total of 35 diagonals. The downward diagonals are depicted in green on the left, while upward diagonals are shown in purple on the right. A small circle denotes the lattice point at which each diagonal originates.

5 Open questions

1. Is T (h, w) = D(h, w) for all odd numbers h, w ∈ ℤ^{+}? That is, can a braided solution provide the maximum number of diagonals in an array for any h, w odd? If so, we can use Proposition 13 to obtain a general formula for D.

2. Is it true that the upper bound for D(2n, 2m, 2k) in Proposition 14 is a lower bound as well? Is there a straightforward generalization of the two-dimensional L-arrangement that places the optimal number of diagonals in general even-sided rectangular prisms in 3-D?

3. Does the placement of the optimal number of diagonals in rectangular prisms show some structure that is similar to the braids in the two-dimensional case?

6 Acknowledgments

The authors would like to thank Dr. G. Christopher Hruska and Dr. Jeb Willenbring for fruitful discussions and encouragement during the process of this investigation. The authors thank the referee for valuable suggestions regarding the improvement of this paper.

References

[1] Distinct Diagonals, NRICH enriching mathematics, http://nrich.maths.org/6784.

[2] M. Gardner, Some new results on non-attacking chess tasks, Math Horizons 8 (2001) 10–12.

[3] IBM ILOG CPLEX Optimization Studio, Academic Initiative,

   https://developer.ibm.com/academic/.

[4] S. Kitaev and T. Mansour, The problem of the pawns, Ann. Comb. 8 (2004) 81–91.

[5] V. Kotěšovec, Non-attacking Chess Pieces — Chess and Mathematics, Neohrožující se Kameny — Šach a Matematika, Self-published online book, 6th ed., 2013. Available at

   kotesovec.cz/books/kotesovec_non_attacking_chess_pieces_2013_6ed.pdf.

[6] N. J. A. Sloane, The Online Encyclopedia of Integer Sequences, https://oeis.org.

2010 Mathematics Subject Classification: Primary 05A05; Secondary 05A15, 05B45. Keywords: diagonal placement, maximum independent set, constrained optimization.

(Concerned with sequences \underline{A264041} and \underline{A260690}.)

Received July 25 2016; revised versions received November 13 2016; December 2 2016; December 5 2016. Published in Journal of Integer Sequences, December 27 2016.

Return to Journal of Integer Sequences home page.