[XML-DEV Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
RE: n-Queens Problem
- From: "Costello, Roger L." <costello@mitre.org>
- To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
- Date: Sun, 2 Apr 2017 13:12:44 +0000

David Carlisle wrote a very cool:
… solution that works for
any size chessboard …
Thank you David!
Here is how David models the chessboard:
<n-queens>
<queen
column="1"
row="3"/>
<queen
column="2"
row="1"/>
<queen
column="3"
row="4"/>
<queen
column="4"
row="2"/>
</n-queens>
And here is his (mind-blowing) Schematron schema:
<sch:schema
xmlns:sch="http://purl.oclc.org/dsdl/schematron"
queryBinding="xslt2">
<sch:pattern
id="n-Queens-Problem">
<sch:rule
context="n-queens">
<sch:assert
test="every
$c in 1 to count(queen) satisfies exists(queen[@column=$c])">
There cannot be two queens in the same column.
</sch:assert>
<sch:assert
test="every
$r in 1 to count(queen) satisfies exists(queen[@row=$r])">
There cannot be two queens on the same row.
</sch:assert>
<sch:assert
test="count(queen)=count(distinct-values(queen/(number(@row)
- number(@column))))">
There cannot be two queens on a (falling) diagonal.
</sch:assert>
<sch:assert
test="count(queen)=count(distinct-values(queen/(number(@row)
+ number(@column))))">
There cannot be two queens on a (rising) diagonal.
</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
|

[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
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.
|
|