Re: [xml-dev] n-Queens Problem

From
Thomas Passin <>
To
"" <>
Date
2017-04-02T01:36:50Z
ID
<>
Thread
Re: [xml-dev] n-Queens Problem
It would seem that you could transform Roger's original document 
(miserable though it is) into yours with a previous xslt transformation. 
  That's if its pattern and ordering were to continue as the problem 
goes to higher and higher N.

TomP

On 4/1/2017 6:49 PM, David Carlisle wrote:
> If you use an easier markup, for example
>
> <n-queens>
>   <q c="1" r="3"/>
>   <q c="2" r="1"/>
>   <q c="3" r="4"/>
>   <q c="4" r="2"/>
> </n-queens>
>
>
> which denotes your board with 4 queens in the specified row and
> column, then I think the following single xpath works for any size
> board and evaluates to true if  every column has a queen, every row
> has a queen and the number of distinct  falling and rising diagonals
> with a queen equals the number of queens.
>
> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
>   <xsl:template match="n-queens">
>    <xsl:sequence select="
>    (every $c in 1 to count(q) satisfies exists(q[@c=$c])) and
>    (every $r in 1 to count(q) satisfies  exists(q[@r=$r])) and
>    count(q)=count(distinct-values(q/(number(@r) - number(@c)))) and
>    count(q)=count(distinct-values(q/(number(@r) + number(@c))))
>     "/>
>   </xsl:template>
> </xsl:stylesheet>
>
>
> you could easily make that into a schematron assertion.
>
>
> On 1 April 2017 at 23:19, David Carlisle <> wrote:
>>
>>>      <column1><row>3</row></column1>
>>
>> why the horrible asymmetry in the markup, with the column number in the
>> element name and the row number in element content?
>> That defeats most ways of shortening the schema by exploiting the symmetry
>> in the problem.
>>
>> David