OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
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.


On 4/1/2017 6:49 PM, David Carlisle wrote:
If you use an easier markup, for example

  <q c="1" r="3"/>
  <q c="2" r="1"/>
  <q c="3" r="4"/>
  <q c="4" r="2"/>

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))))

you could easily make that into a schematron assertion.

On 1 April 2017 at 23:19, David Carlisle <d.p.carlisle@gmail.com> wrote:

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.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS