[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: n-Queens Problem

  • From: Thomas Passin <list1@tompassin.net>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Sat, 01 Apr 2017 21:36:50 -0400

Re:  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]


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.