|
Implementations | ||||||||||||||||
Tests | BaseX 7.7 XQ30 |
EMC/xDB xDB_main_r2411365 XQ30 |
Saxon-EE 9.5.1.1 XP20 |
Saxon-EE 9.5.1.1 XQ10 |
Saxon-EE 9.5.1.1 XP30 |
Saxon-EE 9.5.1.1 XQ30 |
Saxon-EE 9.5.1.4 XQX30 (QT3 v1.1) |
XmlPrime 3.0.0.0 XP30 (QT3 vCVS) |
XmlPrime 3.0.0.0 XQ30 (QT3 vCVS) |
XmlPrime 3.0.0.0 XQX30 (QT3 vCVS) |
XmlPrime 3.0.0.0 XP20 (QT3 vCVS) |
XmlPrime 3.0.0.0 XQX10 (QT3 vCVS) |
XmlPrime 3.0.0.0 XQ10 (QT3 vCVS) |
Zorba 2.9 XQ10 (QT3 vCVS) |
Zorba 2.9 XQ30 (QT3 vCVS) |
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
app-Demos | 3/4 | 3/4 | 0/0 | 4/4 | 0/0 | 4/4 | 4/4 | 0/0 | 4/4 | 4/4 | 0/0 | 4/4 | 4/4 | 4/4 | 4/4 | 3/15 |
sudoku[+]
X sudoku: declare namespace fn = "sudoku"; declare variable $board as xs:integer+ := ( 1,0,0, 3,0,0, 6,0,0, 0,2,0, 5,0,0, 0,0,4, 0,0,9, 0,0,0, 5,2,0, 0,0,0, 9,6,3, 0,0,0, 7,1,6, 0,0,0, 0,0,0, 0,0,0, 0,8,0, 0,4,0, 9,0,0, 0,0,5, 3,0,7, 8,0,0, 4,0,6, 0,0,0, 3,5,0, 0,0,0, 0,0,1); declare variable $rowStarts as xs:integer+ := (1, 10, 19, 28, 37, 46, 55, 64,73); declare variable $groups as xs:integer+ := ( 1,1,1, 2,2,2, 3,3,3, 1,1,1, 2,2,2, 3,3,3, 1,1,1, 2,2,2, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 4,4,4, 5,5,5, 6,6,6, 4,4,4, 5,5,5, 6,6,6, 7,7,7, 8,8,8, 9,9,9, 7,7,7, 8,8,8, 9,9,9, 7,7,7, 8,8,8, 9,9,9 ); declare function fn:getRow ($board as xs:integer+, $index as xs:integer) as xs:integer+ { let $rowStart := floor(($index - 1) div 9) * 9 return one-or-more($board[position() > $rowStart and position() <= $rowStart + 9]) }; declare function fn:getCol ($board as xs:integer+, $index as xs:integer) as xs:integer+ { let $gap := ($index - 1) mod 9, $colIndexes := for $x in $rowStarts return $x + $gap return one-or-more($board[position() = $colIndexes]) }; declare function fn:getGroup ($board as xs:integer+, $index as xs:integer) as xs:integer+ { let $group := $groups[$index] return one-or-more($board[for $x in position() return $groups[$x]= $group]) }; declare function fn:getAllowedValues ($board as xs:integer+, $index as xs:integer) as xs:integer* { let $existingValues := (fn:getRow($board, $index), fn:getCol($board, $index), fn:getGroup($board, $index)) return for $x in (1 to 9) return if (not($x = $existingValues)) then $x else () }; declare function fn:tryValues($board as xs:integer+, $emptyCells as xs:integer+, $possibleValues as xs:integer+) as xs:integer* { let $index as xs:integer := $emptyCells[1], $newBoard as xs:integer+ := ($board[position() <$index], $possibleValues[1], $board[position() > $index]), $result as xs:integer* := fn:populateValues($newBoard, $emptyCells[position() != 1]) return if (empty($result)) then if (count($possibleValues) > 1) then fn:tryValues($board, $emptyCells, one-or-more($possibleValues[position() != 1])) else () else $result }; declare function fn:populateValues($board as xs:integer+, $emptyCells as xs:integer*) as xs:integer*{ if (not(empty($emptyCells))) then let $index as xs:integer := exactly-one($emptyCells[1]), $possibleValues as xs:integer* := distinct-values(fn:getAllowedValues($board, $index)) return if (count($possibleValues) > 1) then fn:tryValues($board, one-or-more($emptyCells), one-or-more($possibleValues)) else if (count($possibleValues) = 1) then let $newBoard as xs:integer+ :=($board[position() < $index], exactly-one($possibleValues[1]), $board[position() > $index]) return fn:populateValues($newBoard, $emptyCells[position() != 1]) else () else $board }; declare function fn:solveSudoku ($startBoard as xs:integer+) as xs:integer+{ let $emptyCells as xs:integer* := for $x in (1 to 81) return if ($startBoard[$x] = 0) then $x else (), $endBoard as xs:integer* :=fn:populateValues($startBoard,$emptyCells) return if (empty($endBoard)) then $startBoard else one-or-more($endBoard) }; declare function fn:drawResult ($board as xs:integer+) as element(){ <html><head><title>Sudoku - XSLT</title><style>table {{ border-collapse: collapse; border: 1px solid black; }} td {{ padding: 10px; }} .norm {{ border-left: 1px solid #CCC; border-top: 1px solid #CCC; }} .csep {{ border-left: 1px solid black; }} .rsep {{ border-top: 1px solid black; }}</style></head><body>{fn:drawBoard($board)}</body></html> }; declare function fn:drawBoard ($board as xs:integer+) as element(){ <table>{for $i in 1 to 9 return <tr>{for $j at $p in 1 to 9 let $pos := (($i - 1) * 9) + $j return <td class="{if ($p mod 3 = 1) then 'csep' else ('norm')} {if ($i mod 3 = 1) then 'rsep' else ('norm')}"> {$board[$pos]}</td> }</tr> }</table> }; fn:drawResult(fn:solveSudoku($board)) |
pass | pass | pass | n/a
notXP20 |
pass | n/a
notXP30 |
pass | n/a | pass | pass | n/a | pass | pass | pass | pass | |
currencysvg[+]
X currencysvg: |
pass | pass | pass | n/a
notXP20 |
pass | n/a
notXP30 |
pass | n/a | pass | pass | n/a | pass | pass | pass | pass | |
itunes[+]
X itunes: |
no result | fail | pass | n/a
notXP20 |
pass | n/a
notXP30 |
pass | n/a | pass | pass | n/a | pass | pass | pass | pass | |
raytracer[+]
X raytracer: import module namespace raytracer="http://www.xqsharp.com/raytracer"; import module namespace scene="http://www.xqsharp.com/raytracer/scene"; declare variable $width := 64; declare variable $height := 64; declare variable $input-context := .; declare variable $scene := scene:prepare-scene($input-context/scene); string-join( ( "P3", string-join((string($width), string($height)), " "), "255", (: : Now the pixel data. We take each pixel in the image, and recenter it, so that the : y co-ordinate ($y-recentered) ranges from -0.5 at the bottom of the image, to 0.5 : at the top of the image. : : The aspect ratio is used to "stretch" the range of x-coordinate values to stop the : image from being skewed. :) let $aspect-ratio := $width div $height for $y in 1 to $height let $y-recentered := ((-$y div $height) + 0.5) for $x in 1 to $width let $x-recentered := (($x div $width) - 0.5) * $aspect-ratio return (: plot-pixel returns us the rgb values of the color of this pixel. We convert these to an integer value in the range [0, 255], and output them. :) string-join( for $channel in raytracer:plot-pixel($scene, $x-recentered, $y-recentered) return string(floor($channel * 255)), " ") ), "
" ) |
pass | pass | pass | n/a
notXP20 |
pass | n/a
notXP30 |
pass | n/a | pass | pass | n/a | pass | pass | pass | pass |