Re: Sudoku - A solution in XSLT 22006-02-16 07:18:42
This is a great idea :) seems so obvious now....
Also, if you process the center cells first you reduce the processing
time considerably (by around a second in my simple tests).
Replace the solveSoduko function with this one (and implement Davids
suggestions):
<xsl:function name="fn:solveSudoku" as="xs:integer+">
<xsl:param name="startBoard" as="xs:integer+"/>
<!-- First process the center cells, then do the rest of the board -->
<xsl:variable name="centerCells" select="for $x in 1 to 81 return
$x[$groups[$x] = 5]" as="xs:integer+"/>
<xsl:variable name="theRest" select="for $x in 1 to 81 return
$x[$groups[$x] != 5]" as="xs:integer+"/>
<xsl:variable name="emptyCells" select="for $x in (centerCells,
$theRest) return if ($startBoard[$x] = 0) then $x else ()"
as="xs:integer*"/>
<xsl:variable name="endBoard" select="fn:populateValues($startBoard,
$emptyCells)" as="xs:integer*"/>
<xsl:choose>
<xsl:when test="empty($endBoard)">
<xsl:message>! Invalid board - The starting board is not
correct</xsl:message>
<xsl:sequence select="$startBoard"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$endBoard"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
cheers
andrew
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
|
|
||||||||||||||||