Sudoku: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) m →{{header|Perl 6}}: flatten output from cross-product operators |
m →{{header|Sidef}}: minor code simplfications |
||
Line 8,974:
=={{header|Sidef}}==
{{trans|Perl 6}}
<lang ruby>func
var (id, im) = i.divmod(9)
var (jd, jm) = j.divmod(9)
jd == id && return true
jm == im && return true
var id2 = id//3
var jd2 = jd//3
jd2 == id2 || return false
jm//3 == im//3
Line 8,990:
func solve(board) {
for i in ^board
board[i] && next
var *t = board
{ |k|
t.contains(k) && next
board[i] = k
solve(board)
} * 9
board[i] = 0
return
}
for i in ^board {
print "#{board[i]} ";
print " " if (3 -> divides(i+1))
print "\n" if (9 -> divides(i+1))
print "\n" if (27 -> divides(i+1))
}
}
Line 9,028 ⟶ 9,024:
9 6 0 0 1 0 3 0 0
0 5 0 6 9 0 0 1 0
)
solve(board)
{{out}}
<pre>5 3 9 8 2 4 7 6 1
|