An interactive companion

Greedy Queens and the Golden Ratio

Place a queen in each successive column of an infinite chessboard, always in the lowest row that no earlier queen attacks. The queens settle along two lines, of slopes and , and never stray far from them.

1The greedy rulePaper §1–2

One queen per column, as low as possible

Number the rows and columns of a quarter-infinite chessboard , with the origin at the lower left. Put a queen at the origin. Then, in column , column , and so on, put a queen in the lowest square that no earlier queen attacks along a row, a diagonal or an antidiagonal.

This is OEIS A275895. Antti Karttunen introduced the positive-integer version, A065188, in 2001.Writing for the row of the queen in column , the rule produces Each earlier queen attacks at most three squares of a column, so some square is always free and every column gets a queen. Less obviously, every row eventually gets one too: Lemma 4 shows that is a permutation of .

Step through the rule below. In the highlighted column, a cross marks each square that an earlier queen attacks, and the gold square is the lowest one left. Hover overTap a cross, or a row number, to see the queen responsible.

The greedy rule, column by column. It starts at column , where all three kinds of attack occur; Figure 1 of the paper shows column , where every square below the queen lies in a row that is already taken. The color of a cross gives the line of attack: gray along a row, orange or teal along a diagonal below or above the line , indigo along an antidiagonal. Use the arrow keys to step, and the space bar to play. With sound on (the speaker at the top of the page), each attacked square ticks and each queen lands with a knock: bright for upper queens, warm for lower ones.

A queen is upper if it lies above the diagonal and lower if it lies below. Let the rule run for a while and a pattern appears: The upper queens climb steeply, the lower ones more gently, and both families seem to follow straight lines.

2Two golden linesPaper, Theorem 1

The queens never stray far from two lines

Here , and .Dekking, Shallit and Sloane conjectured that the upper and lower queens stay within a bounded distance of the lines and , where is the golden ratio. The paper proves it.

Theorem 1

For every ,

From far away the queens look like two straight rays, as in the picture at the top of this page. The figure below subtracts the rays: For each column it plots how far the queen lies above or below its line. Over a thousand columns or a million, the points fill two thin horizontal strips that do not widen.

The distance from each queen to its line, with a histogram of the distances on the right. Shaded: the bounds of Theorem 1. Gold: the sharper bounds of Theorem 2. Dashed: the ranges that Knuth observed for the first columns, which Theorem 2 proves for every column. HoverTap to read off single columns, or press play to add the queens column by column. With sound on, each queen sounds a note, bright for an upper queen and warm for a lower one, higher the further above its line it lies.

Knuth states his ranges in -indexed coordinates, ; the figure converts them. See the remark at the end of Section 3.Knuth's dashed ranges contain every point of the figure, but by themselves they are observations, not theorems. The gold lines come from the paper's second theorem, which sharpens the constants of the first.

Theorem 2

For every , numerically, rounding outward, and .

The gold lines lie inside Knuth's dashed ranges, so his ranges hold in every column, not only in the first . Chapter 10 follows its proof (Section 6.6), which reuses the states of the finite check of Chapter 9. The new bounds are close to the truth: In the first columns, the highest upper queen comes within of its gold line, and the lowest lower queen within of its gold line.

The rest of this page follows the proof of Theorem 1, which has two halves. A counting argument (Chapters 3 to 5) derives the golden lines from one bound on the lower queens. A finite computation and an induction (Chapters 6 to 9) prove that bound. The map below shows how the pieces fit; each box links to its chapter. Chapter 10 then proves Theorem 2 with a second contraction.

The proof at a glance.Chapter 10 proves Theorem 2 from the same checked states. Chapters 11 and 12 are side trips: the queens as a game, and a fast way to generate them.

First, the upper queens, which are much simpler than the lower ones.

3Upper queensPaper §2

Upper queens take the diagonals in order

Number the upper queens from left to right. The upper diagonals are used in the same order.

Lemma 3

The th upper queen lies on the th upper diagonal: If it is in column , its row is .

The identity is implicit in Knuth's program infty-queens.The proof is an induction. Only upper queens lie on upper diagonals, and the first of them hold diagonals to , so the th upper diagonal is still free. When the th upper queen is placed in column , those diagonals block rows to of that column. Every earlier queen lies below and to the left of the square , so none of them shares its row or its antidiagonal, and the greedy rule takes it.

Write for the number of upper queens in columns to . An upper queen in column is the th, so it sits in row : The upper queens are determined by the single count . In the figure below, each curve joins an upper queen's column to its row. The th curve lands places to the right of where it starts, so the curves never cross.

Columns and rows of the upper queens (teal). The rows that no curve reaches are the lower rows. Move the slider to see Lemma 5: The th smallest lower row is . Hover overTap a curve to read it.

The rows that the curves miss are exactly the lower rows, and the figure shows why they are easy to count. Upper queens in columns before land below row , and the later ones land above it, so that row is the th lower row. This is a case of the Lambek–Moser theorem on complementary sequences.

The lower queens themselves are another matter. Their rows are not in increasing order, and nothing as simple as Lemma 3 places them.

4The heart of the proofPaper §3

One bound on the lower queens

Number the lower queens from left to right. The th lower queen, at , lies on the lower diagonal , and is its magnitude. If lower queens used the lower diagonals in order, as upper queens do, we would have . They do not, but they come close.

Lemma 6 (bounded diagonal discrepancy)

For every , .

The paper calls this bound the heart of its result. Chapter 5 shows how it forces the golden ratio, and Chapters 7 to 9 show how it is proved. In the figure, each strand runs from the th lower queen to its magnitude . Strands cross only near neighbors, and none travels more than four places.

The permutation of the lower queens, colored by : indigo below zero, orange above. Below, a strip of the values for the first lower queens (drag to move the window), and how often each value occurs among the lower queens in the first million columns.

The values and never occur. This is no accident of the first million columns: The checked states of Chapter 9 show that always (Section 6.6). The same checked states also show that the least unused magnitude never falls more than four behind , so the magnitudes run through every positive integer; with Lemma 3, every diagonal of the board holds exactly one queen (Corollary 19).

5Why the golden ratioPaper, Proposition 9

How one bound forces the golden ratio

Let count the lower queens in columns to . Sorting the lower queens by row, with Lemma 5, turns the bound of Chapter 4 into an estimate for the columns of the lower queens (Lemma 7). From that estimate, Lemma 8 derives a relation between the counts and :

Why does this force ? Suppose that were exactly for some slope . Then , and Drag the slope (drag the gold number sideways, or focus it and use the arrow keys): with 0.600, the coefficient is 0.0400, which is positive. A bounded needs the coefficient to vanish, so and .

The paper makes this exact. Put . Substituting into the definition of , and using , gives The error at is a copy of the error at , shrunk by the factor , plus a new term of at most . Follow down to , where the error is . The new terms add up to less than

The error for up to a million (gray), with the chain (teal) for a chosen starting column; clicktap the plot to start elsewhere. Each hop divides by about . Shaded: the bound . The table checks the identity above at every hop. When you choose a column, a light runs down the chain; with sound on, each landing is a note.

For an upper queen, exactly, because and . That is the upper half of Theorem 1. For a lower queen, differs from by , which Chapter 4 bounds by ; that is the lower half.

6The queen wordPaper, Definition 10

Four symbols per index

To prove the bound of Chapter 4, the paper describes the board by a word. For each index it records two bits: The column bit is when column holds an upper queen, and the row bit is when row does. The queen word is , with symbols

Column and row meet on the diagonal. Hover overTap the board or the word to choose . The strip under the board shows the column bits , and the strip beside it the row bits ; teal means an upper queen. With sound on, each symbol sounds as one of four notes, the same four as in the history graph of Chapter 8; the play button plays , and you can hear the uneven rhythm of upper and lower queens. The board zooms out as grows, keeping both queens in view.

Before column , the symbols are already fixed: Each column is filled, and an upper queen in row must lie in a column less than . The two bits are what the proof needs to know about upper queens. By Lemma 3, the upper queens are determined by counts of column bits, and a lower candidate square can be blocked by an upper queen in its row, which is a row bit.

The step in column uses the word in two places. It reads near the least unused row , where the lower candidates are, and it writes the new symbol . Since is about , the two places drift apart as grows. The proof stores only short pieces at each end, and near and just before , and has to cope without the long stretch in between.

The queen word before column , with the pieces that the local state keeps. Press play: The gap grows in proportion to , since tends to . The next two chapters explain the pieces and how the calculation manages without the gap.
7Eight recordsPaper §4–5

A calculation on eight records

The greedy step in column consults every earlier queen, and the board keeps growing. To prove a bound that holds in every column, the paper replaces the board by a local state (Definition 11): eight records, measured from three references that move as the queens are placed. They are the column , the least unused row , and the least unused lower-diagonal magnitude .

Lower candidates. Every row below is used, and so is every lower diagonal of magnitude less than . A lower queen in column must therefore go in a row from to , at an offset above , where . The sets , and record the rows, diagonals and antidiagonals of the earlier lower queens that could still attack these candidates, as offsets from , and . The records also give the discrepancy directly: If the new queen is the th lower queen, at offset , then So the heart of the proof reduces to bounds on two records. If and in every column, then .

Upper queens. Rather than store their positions, the state stores pieces of the queen word. The input history and the queue start near index and answer the candidates' row and antidiagonal tests. The output history holds the last twelve symbols before . One more number, , locates column among the upper queens, and this is all that Proposition 13 and Proposition 14 need.

The calculation. From the records alone, the calculation (Algorithm 1) finds the queen in column and the records before column , in four stages. Choose the queen: Test the lower candidates from the lowest up, first against the lower queens recorded in , and , then against the upper queens, using the stored symbols of the queen word; if every candidate is attacked, the queen is upper. Write the new symbol , and check that the history graph allows it after . Move the references: If the new queen fills row or the diagonal of magnitude , that reference advances to the next unused one, and the offsets shift to match. Move the words: The symbols that has passed leave for , and gains .

The calculation never uses , or . It reads only the records, so it can be run on any state, whether or not the state comes from a real board. Sometimes a test needs a symbol beyond the end of , which the records do not hold. The calculation then makes a request to the history graph of Chapter 8, which lists the symbols that may come next, and when the graph allows several it branches and follows each one. Column is an example.

The calculation on the records before a column (Algorithm 1), stage by stage. Press play, or clicktap a step, to see what it tests; at the last step the card shows the records it produces, with the changes marked. The board shows what the records mean: the rows from up, the lines of the recorded lower queens, and the queen word underneath, column by column. What the calculation sees hides everything it cannot read. The four presets are the worked examples of Section 4.6.
Condition 16 and Lemma 17

Suppose the records before column satisfy that and , and that follows the history graph. Then the branch that answers every request with the actual symbol never stops, places the actual queen in column , and produces the actual records before column .

The figure above follows this actual branch. The bounds do two jobs. They keep every requested symbol within six places of , and together with they put at least eight places beyond , so every requested symbol is already determined. They also ensure that no unstored upper queen can affect a test. The condition holds from column on, since never decreases. What remains is to show that the bounds hold in every column. Since the calculation cannot tell which branch is the actual one, the paper checks them for every branch.

8The history graphPaper §4.3, §6.2

What may come next

The records keep the queen word only near index and just before , and the two ends drift apart: is before column and before column . So when the calculation needs a symbol past the end of , the records do not have it. The paper's answer is a finite history graph (Definition 12). Its vertices are words of twelve symbols, and an edge says that the symbol may follow the twelve symbols of ; the destination drops the oldest symbol and appends . A request is answered by the edges leaving the twelve symbols just read. At the other end, the output check confirms that the new symbol labels an edge leaving .

The figure places each vertex by its bits. Its column bits, newest first, give the horizontal coordinate as a binary fraction, and its row bits give the vertical one. The four quadrants hold the windows ending in , , and . Each quadrant splits in the same way by the symbol before, and so on. An edge appends a symbol, which halves both coordinates and moves the point toward the corner of the new symbol: It is one jump of the "chaos game".

The vertices and edges of the history graph. Teal: windows that the queen word passes through in its first million symbols, darker for more visits. Orange: windows the graph allows but the word never reaches there. Play the walk to follow the queen word through the graph, or replay the construction. Hover overTap a point to read its window.

The paper finds the graph by running the calculation itself (Algorithm 2). It starts from the eighteen windows of . Whenever a branch computes a symbol with no edge, it adds the edge instead of failing, and it repeats over all the states found so far until nothing new is added. Thirteen explorations add edges, and the fourteenth adds none. The construction only finds the graph. The proof holds the finished graph fixed and checks it.

The graph allows more than the queen word does. It has windows that never occur in and edges that never uses, because the state omits most of the board, so its records and the symbols it reads can combine in ways the board never produces. That is the price of a finite description, and the check in the next chapter has to cover all of these combinations.

9Checking every branchPaper §6.3–6.4

A finite check, and an induction

Start from the state before column , computed directly from the first thirty queens. Run the calculation on it, following every branch; run it on every successor; and continue until no new state appears (Algorithm 3). The check has no depth limit, and it never drops a branch.

Proposition 18 (finite verification)

With the history graph fixed, the calculation from the state before column reaches states and state-graph edges. Every branch passes the output check, and every successor satisfies Condition 16.

You can run the check yourself. The code behind it is a TypeScript port of the companion repository's verifier, and it reproduces the counts of Section 6.

The exhaustive check, run by this page. Each cell counts the reached states with a given and , filled in the order the exploration found them. The gold box is Condition 16; the check finds no state outside it.

An induction (Section 6.4) now follows the actual queens forever. Suppose that, before column , the actual records are one of the checked states and follows the history graph. Since from column on, Lemma 17 applies, and the actual branch carries out the actual step. By the check, its new symbol passes the output check, and its successor is again a checked state. Both assumptions therefore hold before column . At each lower queen from column on, the records give with and ; the lower queens before column are checked directly. This proves the bound of Chapter 4.

Why twelve symbols?

Shorter windows give a smaller graph, but it allows too much. The calculation can then read combinations of symbols that the board never produces, and some of them push the records out of bounds. Choose a length to rerun the construction in your browser.

The construction with histories of to symbols, as in the companion's history-length experiment (Appendix A2). Lengths to reach a state whose successor breaks Condition 16; lengths , and close.
10Knuth's rangesPaper §6.6

A second contraction

The contraction of Chapter 5 charges every hop its worst case, a new term as large as . Those worst cases never line up, and the queens use only a third of the band they allow: For the upper queens of Chapter 2, stays between and , inside a band of . To prove Theorem 2, the paper uses a second contraction. It hops from column to the least unused row , and it keeps track of which worst cases can occur together. The error is the same as in Chapter 5: , where counts the upper queens in columns to .

Lemma 21 (one-step error identity)

Before column , with least unused row and records , and , where .

The records count the queens. The lower queens in columns to use every lower diagonal of magnitude less than , and the magnitudes recorded in , so there are of them. With , this gives . The record ties column to the count at . Writing both counts through and using leaves the identity.

Compare it with Chapter 5. This hop goes only to , not to , so it shrinks the earlier error only by . It also flips the sign: A high error at pushes the error at down. The new term depends only on the state before column , and over the checked states of Chapter 9 it takes just values, from to . Bounding and separately would give only , which is worse than Theorem 1.

The two terms are not independent. The twelve symbols before index are the input history of the state before column , and they are also the output history of the state before column : So one window of the queen word constrains both the state at , and with it , and the error at . The paper therefore gives every vertex of the history graph, a possible window of twelve symbols, an interval . It is meant to contain whenever the twelve symbols before column are .

Suppose the interval holds before column , at the window . The identity sends it to an interval for : The map flips it, shrinks it by and shifts it by . The bounds are consistent (Definition 22) if, at every state of the state graph, this image lands inside the interval at : with . That is one finite condition per state. Consistent bounds that hold before columns to then hold before every column, by strong induction (Lemma 23): From column on, the least unused row is at least , so the interval at already holds before column , and consistency carries it to column .

The second contraction. Gray: the error before every column up to a million. The chain hops from column to its least unused row , then to the least unused row before column , and so on, down to one of the columns to , which are checked directly (hollow). Gold bars: the interval of the twelve symbols before each column of the chain, which contains the point. Dashed: the least and the greatest over all windows. Below, one hop at a time: The interval at (teal) is flipped, shrunk by and shifted by , and lands inside the interval at (gold); the actual errors (black) follow the same map. Use the slider, or clicktap the plot, to start from another column, and choose a point or a row of the table to see its hop. The default is the column of Chapter 5.

Where do the intervals come from? Applying the identity again at , then at the least unused row before , and so on, writes the error as an alternating sum along the chain, in which each state has as input history the output history of the next. The paper takes and to be the least and greatest such sums over every chain of states that the state graph allows from . It computes them in rounds, adding one state to the chains at a time: over the states with output history , starting from . The rest of the chain enters with a minus sign, so the least sum takes the greatest rest, and the greatest sum the least. The rounds converge geometrically, and their limits are consistent, since each state is one of the terms in the minimum and the maximum. Each limit is attained by one state, and following those states runs around a cycle; solving around the cycle gives the exact values, all in .

The last step reads off Theorem 2. For an upper queen in column , (Chapter 5), and this lies in the interval of the window , which ends with the symbol of an upper column. For a lower queen at offset above , the definition of gives with in the interval of . So the bounds of Theorem 2 follow from a check of every window that ends in an upper column, and of every lower choice of every state.

Proposition 24 (finite verification of the window bounds)

There are consistent window bounds, with values in , that hold before columns to , such that (i) every window whose last symbol has column bit has and , and (ii) at every lower choice of every state , at offset , with ,

You can run this check too. It explores the state graph as in Chapter 9, computes the window bounds exactly, and checks every condition in exact arithmetic, as the companion repository's knuth_ranges.py does.

The check of Proposition 24, run by this page. Each bar is one interval, sorted by midpoint: for (i), the window bounds of a window that ends in an upper column, which contain ; for (ii), the bounds on at one lower choice. Gold lines: the constants of Theorem 2. Every bar lies between them, and the gold bars reach them, at the gold dots. Dashed: Knuth's ranges. Hover overTap a bar to read its interval.

The intervals reach the constants, but the queens do not, so the inequalities of Theorem 2 are strict. The upper constants have a positive coefficient of , and has a negative one. The lower constants could equal only at or , and the columns before are checked directly. The queens do come close: In the first columns, the highest upper queen comes within of , and the lowest lower queen within of . Since the gold lines lie inside Knuth's dashed ranges, his observation holds in every column.

11A game in disguisePaper §1, game remark

The queens as a game

The greedy queens also solve a game. A single queen stands on the board. Two players take turns moving it any number of squares to the left, down, diagonally down and to the left, or diagonally up and to the left, and the player who cannot move loses. Every move decreases , so the game always ends.

The losing positions, from which the player to move loses against best play, are exactly the greedy queens . No move joins two of them, because the queens do not attack one another. From any other square there is a move to one. If , move down to . If , the greedy rule passed over because an earlier queen attacks it, and that queen is one move away.

In the language of combinatorial game theory, the queens are the P-positions, where the previous player, the one who just moved, wins. Every other square is an N-position, where the next player wins.These two facts give the winning strategy: Move to a greedy queen every time. Your opponent then always stands on a queen, and every move from it lands on a square that is not a queen; from there you move back onto a queen. The game cannot last forever, so in the end your opponent stands on a queen with no move at all, the origin , and loses. The strategy is also the only way to win against an opponent who plays perfectly. Move once to a square that is not a queen, and your opponent moves to a queen and plays the same strategy against you.

Play against an opponent who knows where the queens are. You move first, from a square that is not a queen, so you can win by moving to a greedy queen every time; a single move to any other square hands the win to your opponent. The messages explain each move. Tick the box to see the queens.

Combinatorial game theory gives every square a Sprague–Grundy value : the least nonnegative integer that is not the value of a square one move away. The losing squares are those with , the greedy queens, and Theorem 1 locates this zero set. The positive values are harder to describe. Every value occurs exactly once in each row and each column; Dekking, Shallit and Sloane conjectured that it also occurs exactly once on each diagonal, and Corollary 19 proves this for the value .

Sprague–Grundy values for columns to and rows to , darker for larger values. The squares with the chosen value are highlighted: gold for , the greedy queens, and orange otherwise. ClickTap a square to highlight its value. Zoom with the buttons or Ctrl + scroll, and drag to panPinch or use the buttons to zoom in: Close up, each square shows its value, and the lines from the chosen square are its moves. Its value is the least number that no square on those lines has.
12Little memoryPaper §7

A million queens from a few dozen records

The local description also gives a fast way to compute the queens. The calculation for column reads the queen word only up to about index , and . So the symbols it needs can be regenerated by a second copy of the same calculation, running behind the first. That copy needs symbols near , supplied by a third copy, and so on. Each copy receives the actual symbols and follows the actual branch, so nothing is guessed and the history graph is not needed.

When the first copy reaches column , the second is near , the third near , and so on until a copy is still within its first eighteen columns, so the chain has about copies: for a million queens. Their combined work is about queen placements, and no copy keeps more than a handful of small records.

A chain of copies, running in your browser. This is Algorithm 4, with symbols passed one at a time; each copy keeps only the records in the table, whatever the number of queens. Each arc runs from where a copy works to where it reads, which is where the next copy works (compare Figure 9).

The paper goes further. Whenever a copy pauses for input, its records take one of only values, so the calculation can be compiled into a table that places several queens per lookup (Section 7.3), and the copies pass symbols four at a time through buffers (Section 7.4). The C implementation in the companion repository generates ten billion queens in about seconds using MiB of memory. A bit-packed adaptation of Knuth's program takes about seconds and GiB.

13Further

Read further

The paper · arXiv:2609.31336 Greedy queens and the golden ratio The full proofs, the construction of the history graph, the consequences for OEIS sequences, the proof of Knuth's ranges, and the fast generator. The code github.com/boonsuan/queens The two independent verifiers of Section 6, the checks behind both theorems, the OEIS checks, and the C generator with its benchmarks. Each folder has its own README. The sequence OEIS A065188 and A275895 The greedy queens permutation, with the related sequences A275884–A275892, several of whose questions the paper settles.

Everything on this page is computed in your browser from the definitions. The queens come from the greedy rule. The explorer, the history graph and the check use a TypeScript port of the companion repository's verifier, which reproduces the counts of Section 6 and the positions of the copies in Figure 9 of the paper. The page needs no server and works offline.

About this companion

Designed and built by Claude Opus 5.5

This companion was designed, written and built by Claude Opus 5.5, an AI model made by Anthropic, at the request of the paper's author, Boon Suan Ho. Claude chose the chapters and the figures, wrote the prose, drew the visual design, and wrote all of the code: the widgets, and the TypeScript port of the verifier that runs the exhaustive check in your browser. The author gave the brief and reviewed the result.

The mathematics is the paper's. Every claim on this page was checked against it, and the port reproduces its numbers, from checked states to the positions of the copies in Figure 9. For the proofs, the paper is the authority.