------------------------------------------ ------------soluzione Lapo Cioni (2015/16) ----Sudoku F=QQ[x_(1,1)..x_(9,9)] gens F I=ideal(0) g=(i->(i-1)*(i-2)*(i-3)*(i-4)*(i-5)*(i-6)*(i-7)*(i-8)*(i-9) ) h=(i->(i-1)*(i-2)*(i-3)*(i-4)*(i-5)*(i-6)*(i-7)*(i-8) ) l=((i,j)->h(i-j)*h(j-i)) for i from 1 to 9 do for j from 1 to 9 do I=I+(g(x_(i,j))) --colori possibili for i from 1 to 9 do (for j from 1 to 9 do (for k from j+1 to 9 do I=I+l(x_(i,j),x_(i,k)))) --un solo numero per riga for i from 1 to 9 do (for j from 1 to 9 do (for k from j+1 to 9 do I=I+l(x_(j,i),x_(k,i)))) --un solo numero per colonna f=(i->(if i<=3 then 1 else if i>=7 then 3 else 2 , if i<=3 then i else if i>=7 then i-6 else i-3 )) --funzione che associa a i=1..9 una coordinata del quadrato 3x3 for t from 0 to 2 do ( for s from 0 to 2 do (for i from 1 to 9 do ( for k from i+1 to 9 do ( --un solo numero per quadrato 3x3. n.b. scriviamo piu' volte alcuni ideali a=x_((f(i))_(0)+3*t,(f(i))_(1)+3*s) , b=x_((f(k))_(0)+3*t,(f(k))_(1)+3*s) , I=I+(l(a,b)) )))) betti I -----da qui in poi si inseriscono i dati del problema I=I+(x_(1,1)-9)+(x_(1,3)-7)+(x_(2,3)-5)+(x_(3,2)-8)+(x_(3,4)-5)+(x_(3,5)-1)+(x_(1,7)-8)+(x_(1,9)-1)+(x_(2,7)-3)+(x_(3,8)-2)+(x_(5,3)-3)+(x_(6,3)-2)+(x_(4,6)-4)+(x_(5,5)-7)+(x_(6,4)-1)+(x_(4,7)-6)+(x_(5,7)-9)+(x_(7,2)-5)+(x_(8,3)-1)+(x_(9,1)-6)+(x_(9,3)-8)+(x_(7,5)-3)+(x_(7,6)-8)+(x_(7,8)-6)+(x_(8,7)-7)+(x_(9,7)-2)+(x_(9,9)-4); xx=transpose genericMatrix(F,9,9) time xx%I----19 secondi