XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
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

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]


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