Dim a(9) As Byte
Dim b(81) As Byte
Dim c(81) As Byte
Dim k(729) As Byte
Dim i, isp
Private Sub Form_Load()
Open "c:\sudoku.txt" For Append As 1
Randomize Timer
gen729
i = 0
p1 = 0
While i < 81
i = i + 1
c(i) = 1
ispravno (p1)
While isp = "ne"
c(i) = c(i) + 1
While c(i) = 10
c(i) = 0
i = i - 1
c(i) = c(i) + 1
Wend
ispravno (p1)
Wend
Wend
Print #1, ""
Print #1, Date;
Print #1, Time
Print #1, ""
For g = 0 To 8
For o = 1 To 9
Print #1, b(g * 9 + o);
If o = 3 Then Print #1, Chr(124);
If o = 6 Then Print #1, Chr(124);
Next
Print #1, ""
If g = 2 Then Print #1, "--------------------------"
If g = 5 Then Print #1, "--------------------------"
Next
Close 1
End
End Sub
Sub ispravno(t)
isp = "da"
For x = 1 To 81
b(x) = 0
Next
For x = 1 To i
p1 = plus(k((x - 1) * 9 + c(x))) + sab(x Mod 9)
If b(p1) <> 0 Then isp = "ne"
b(p1) = Int((x - 1) / 9) + 1
Next
t = p1
y = Int(1 + (t - 1) / 9)
x = t - (y - 1) * 9
If x < 4 Then xx = 1
If x > 3 And x < 7 Then xx = 4
If x > 6 Then xx = 7
If y < 4 Then yy = 1
If y > 3 And y < 7 Then yy = 4
If y > 6 Then yy = 7
For s = (yy - 1) * 9 + xx To (yy - 1) * 9 + xx + 2
If t <> s And b(t) = b(s) Then isp = "ne"
Next
For s = yy * 9 + xx To yy * 9 + xx + 2
If t <> s And b(t) = b(s) Then isp = "ne"
Next
For s = (yy + 1) * 9 + xx To (yy + 1) * 9 + xx + 2
If t <> s And b(t) = b(s) Then isp = "ne"
Next
For s = (y - 1) * 9 + 1 To (y - 1) * 9 + 9
If t <> s And b(t) = b(s) Then isp = "ne"
Next
For s = x To 81 Step 9
If t <> s And b(t) = b(s) Then isp = "ne"
Next
End Sub
Sub gen9()
Dim pom(9)
For q = 1 To 9
a(q) = 0
pom(q) = 0
Next
For q = 1 To 9
ok = 0
While ok = 0
p = Int(Rnd * 9) + 1
If pom(p) = 0 Then pom(p) = 1: a(q) = p: ok = 1
Wend
Next
End Sub
Sub gen729()
For s = 1 To 81
gen9
For t = 1 To 9
k((s - 1) * 9 + t) = a(t)
Next t
Next s
End Sub
Function plus(pk)
If pk = 1 Then plus = 0
If pk = 2 Then plus = 1
If pk = 3 Then plus = 2
If pk = 4 Then plus = 9
If pk = 5 Then plus = 10
If pk = 6 Then plus = 11
If pk = 7 Then plus = 18
If pk = 8 Then plus = 19
If pk = 9 Then plus = 20
End Function
Function sab(lp)
If lp = 1 Then sab = 1
If lp = 2 Then sab = 4
If lp = 3 Then sab = 7
If lp = 4 Then sab = 28
If lp = 5 Then sab = 31
If lp = 6 Then sab = 34
If lp = 7 Then sab = 55
If lp = 8 Then sab = 58
If lp = 0 Then sab = 61
End Function
Gore vam je program u vb za generisanje. Potrebno je samo da kreirate prazan file "c:\sudoku.txt". Nisam se puno zamlacivao sa matematikom ali broj kombinacija je mnogo veci od 16, i reda je velicine 10^21. Program radi vrlo brzo (par desetinki sekunde). Tiranine, odgovor na tvoje pitanje se ne moze dati precizno. Zavisi od toga kako je zagonetka postavljena
Nijedan nepušač još nije preživeo.