Advertisement
logicmoo

Untitled

Oct 21st, 2018
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.55 KB | None | 0 0
  1. import cp.
  2. sudoku =>
  3. instance(N,A),
  4. A in 1..N,
  5. foreach(Row in 1..N)
  6. all_different([A[Row,Col] : Col in 1..N])
  7. end,
  8. foreach(Col in 1..N)
  9. all_different([A[Row,Col] : Row in 1..N])
  10. end,
  11. M=floor(sqrt(N)),
  12. foreach(Row in 1..M, Col in 1..M)
  13. Square = [A[Row1,Col1] :
  14. Row1 in (Row-1)*M+1..Row*M,
  15. Col1 in (Col-1)*M+1..J*M],
  16. all_different(Square)
  17. end,
  18. solve(A),
  19. foreach(I in 1..N) write(A[I]) end.
  20. instance(N,A) =>
  21. N=9,
  22. A={{5,3,_,_,7,_,_,_,_},
  23. {6,_,_,1,9,5,_,_,_},
  24. {_,9,8,_,_,_,_,6,_},
  25. {8,_,_,_,6,_,_,_,3},
  26. {4,_,_,8,_,3,_,_,1},
  27. {7,_,_,_,2,_,_,_,6}}.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement