; begin KiXgolfUDF
;
;!
Function S($o)
Dim $i, $, $k, $t, $x
; Create a loop for the maximum number of x-es. (There are 16 fields)
For $x = 0 to 16
; empty the row, column and square arrays and add one dimension to the solution array for current encountered x.
Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
;loop through each column
For $i = 0 to 3
;loop through each row
For $ = 0 to 3
; retrieve the field from the original array
$t = $o[$i,$]
; find the corresponding square.
; 0 0 1 1
; 0 0 1 1
; 2 2 3 3
; 2 2 3 3
$k = iif($i<2,iif($<2,0,1),iif($<2,2,3))
; fill the row with all variables on that row
$r[$] = $r[$] + $t
; fill the column with all variables in that column
$c[$i] = $c[$i] + $t
; fill the square with all variables in that square
$q[$k] = $q[$k] + $t
; fill the solution array with the current variable
$s[$i, $, $x] = $t
Next
Next
; if there are no more x-es in the rows, exit the function
if instr(join($r),x)=0
exit
endif
For $i = 0 to 3
For $ = 0 to 3
$k=@
; Loop through each possible number (1,2,3 or 4)
for $t = 1 to 4
; If current variable is an x and the number ($t) does not exist in the corresponding row, column or square, add it to the variable $k
if instr($c[$i]+$r[$]+$q[iif($i<2,iif($<2,0,1),iif($<2,2,3))],$t)=0 & $o[$i,$]=x
$k=$k+$t
endif
next
; If there's only one digit in the variable $k, this means that that's the only solution for that x, so we can change that field in the initial array.
if ($k^)=1
$o[$i,$]=$k
; we reset the $i and $j so that we exit these loops and start at the beginning of the $x loop again.
$i=3 $=3
EndFunction
;!
;!
; end KiXgolfUDF