<#37283#>Figure: A chess board with a single queen<#37283#>
The queen-placement problem is to place eight queens on a chess board of
eight-by-eight tiles such that the queens on the board don't threaten each
other. In computing, we generalize the problem of course and ask whether we
can place <#66922#><#37285#>n<#37285#><#66922#> queens on some board of arbitrary size <#66923#><#37286#>m<#37286#><#66923#> by <#66924#><#37287#>m<#37287#><#66924#>.
Even a cursory glance at the problem suggests that we need a data
representation of boards and some basic functions on boards before we can
even think of designing a program that solves the problem. Let's start with
some basic data and function definitions.
<#37290#>Exercise 28.2.1<#37290#>
Solution<#66929#><#66929#>
Next we need a function for creating a board and another one for checking on
a specific tile. Following the examples of lists, let's define
<#66930#><#37302#>build-board<#37302#><#66930#> and <#66931#><#37303#>board-ref<#37303#><#66931#>.
<#37304#>Exercise 28.2.2<#37304#>
<#71536#>;; <#66932#><#37310#>build-board<#37310#> <#37311#>:<#37311#> <#37312#>N<#37312#> <#37313#>(<#37313#><#37314#>N<#37314#> <#37315#>N<#37315#> <#37316#><#37316#><#37317#>-;SPMgt;<#37317#><#37318#><#37318#> <#37319#>boolean)<#37319#> <#37320#><#37320#><#37321#>-;SPMgt;<#37321#><#37322#><#37322#> <#37323#>board<#37323#><#66932#><#71536#>
<#71537#>;; to create a board of size <#66933#><#37324#>n<#37324#><#66933#> x <#66934#><#37325#>n<#37325#><#66934#>, <#71537#>
<#71538#>;; fill each position with indices <#66935#><#37326#>i<#37326#><#66935#> and <#66936#><#37327#>j<#37327#><#66936#> with <#66937#><#37328#>(f<#37328#> <#37329#>i<#37329#> <#37330#>j)<#37330#><#66937#><#71538#>
<#37331#>(define<#37331#> <#37332#>(build-board<#37332#> <#37333#>n<#37333#> <#37334#>f)<#37334#> <#37335#>...)<#37335#>
<#71539#>;; <#66938#><#37336#>board-ref<#37336#> <#37337#>:<#37337#> <#37338#>board<#37338#> <#37339#>N<#37339#> <#37340#>N<#37340#> <#37341#><#37341#><#37342#>-;SPMgt;<#37342#><#37343#><#37343#> <#37344#>boolean<#37344#><#66938#><#71539#>
<#71540#>;; to access a position with indices <#66939#><#37345#>i<#37345#><#66939#>, <#66940#><#37346#>j<#37346#><#66940#> on a-board<#71540#>
<#37347#>(define<#37347#> <#37348#>(board-ref<#37348#> <#37349#>a-board<#37349#> <#37350#>i<#37350#> <#37351#>j)<#37351#> <#37352#>...)<#37352#>
Test them rigorously! Use the strategy of section~#secequaltest#37356> Solution<#66941#><#66941#>
In addition to these generic functions on a chess board representation, we
also need at least one function that captures the concept of a ``threat'' as
mentioned in the problem statement.
<#37362#>Exercise 28.2.3<#37362#>
Solution<#66947#><#66947#>
Once we have data definitions and functions for the ``language of chess
boards,'' we can turn our attention to the main task: the algorithm for
placing a number of queens on some given board.
<#37375#>Exercise 28.2.4<#37375#>
Solution<#66950#><#66950#>