sudoku prolog solver using clpfd library









up vote
-4
down vote

favorite












I found a code to solve the sudoku puzzle in Prolog using clpfd library.



 :- use_rendering(sudoku).

:- use_module(library(clpfd)).
sudoku(Rows) :-
length(Rows, 9), maplist(same_length(Rows), Rows),
append(Rows, Vs), Vs ins 1..9,
maplist(all_distinct, Rows),
transpose(Rows, Columns),
maplist(all_distinct, Columns),
Rows = [A,B,C,D,E,F,G,H,I],
blocks(A, B, C), blocks(D, E, F), blocks(G, H, I).

blocks(, , ).
blocks([A,B,C|Bs1], [D,E,F|Bs2], [G,H,I|Bs3]) :-
all_distinct([A,B,C,D,E,F,G,H,I]),
blocks(Bs1, Bs2, Bs3).

problem(1, [[_,_,_, _,_,_, _,_,_],
[_,_,_, _,_,3, _,8,5],
[_,_,1, _,2,_, _,_,_],

[_,_,_, 5,_,7, _,_,_],
[_,_,4, _,_,_, 1,_,_],
[_,9,_, _,_,_, _,_,_],

[5,_,_, _,_,_, _,7,3],
[_,_,2, _,1,_, _,_,_],
[_,_,_, _,4,_, _,_,9]]).


I need to do this code with different strategies like backtracking, generate and test or back-jumping. can someone help me in this as I am very new to prolog? Your help will be highly appreciated










share|improve this question









New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    Welcome to stackoverflow.com. You might want to read the online help, particularly the section regarding how to ask a good question. As it stands, your question will likely be down-voted due to there no show of what you have tried to solve the problem and lack of a more specific question. In other words, don't approach your question as if you are asking others to do your work for you, but explain what you've investigated, what you've tried, and more specifically where you are stuck. Have you researched backtracking, generate and test, etc, to understand them?
    – lurker
    Nov 9 at 16:44















up vote
-4
down vote

favorite












I found a code to solve the sudoku puzzle in Prolog using clpfd library.



 :- use_rendering(sudoku).

:- use_module(library(clpfd)).
sudoku(Rows) :-
length(Rows, 9), maplist(same_length(Rows), Rows),
append(Rows, Vs), Vs ins 1..9,
maplist(all_distinct, Rows),
transpose(Rows, Columns),
maplist(all_distinct, Columns),
Rows = [A,B,C,D,E,F,G,H,I],
blocks(A, B, C), blocks(D, E, F), blocks(G, H, I).

blocks(, , ).
blocks([A,B,C|Bs1], [D,E,F|Bs2], [G,H,I|Bs3]) :-
all_distinct([A,B,C,D,E,F,G,H,I]),
blocks(Bs1, Bs2, Bs3).

problem(1, [[_,_,_, _,_,_, _,_,_],
[_,_,_, _,_,3, _,8,5],
[_,_,1, _,2,_, _,_,_],

[_,_,_, 5,_,7, _,_,_],
[_,_,4, _,_,_, 1,_,_],
[_,9,_, _,_,_, _,_,_],

[5,_,_, _,_,_, _,7,3],
[_,_,2, _,1,_, _,_,_],
[_,_,_, _,4,_, _,_,9]]).


I need to do this code with different strategies like backtracking, generate and test or back-jumping. can someone help me in this as I am very new to prolog? Your help will be highly appreciated










share|improve this question









New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    Welcome to stackoverflow.com. You might want to read the online help, particularly the section regarding how to ask a good question. As it stands, your question will likely be down-voted due to there no show of what you have tried to solve the problem and lack of a more specific question. In other words, don't approach your question as if you are asking others to do your work for you, but explain what you've investigated, what you've tried, and more specifically where you are stuck. Have you researched backtracking, generate and test, etc, to understand them?
    – lurker
    Nov 9 at 16:44













up vote
-4
down vote

favorite









up vote
-4
down vote

favorite











I found a code to solve the sudoku puzzle in Prolog using clpfd library.



 :- use_rendering(sudoku).

:- use_module(library(clpfd)).
sudoku(Rows) :-
length(Rows, 9), maplist(same_length(Rows), Rows),
append(Rows, Vs), Vs ins 1..9,
maplist(all_distinct, Rows),
transpose(Rows, Columns),
maplist(all_distinct, Columns),
Rows = [A,B,C,D,E,F,G,H,I],
blocks(A, B, C), blocks(D, E, F), blocks(G, H, I).

blocks(, , ).
blocks([A,B,C|Bs1], [D,E,F|Bs2], [G,H,I|Bs3]) :-
all_distinct([A,B,C,D,E,F,G,H,I]),
blocks(Bs1, Bs2, Bs3).

problem(1, [[_,_,_, _,_,_, _,_,_],
[_,_,_, _,_,3, _,8,5],
[_,_,1, _,2,_, _,_,_],

[_,_,_, 5,_,7, _,_,_],
[_,_,4, _,_,_, 1,_,_],
[_,9,_, _,_,_, _,_,_],

[5,_,_, _,_,_, _,7,3],
[_,_,2, _,1,_, _,_,_],
[_,_,_, _,4,_, _,_,9]]).


I need to do this code with different strategies like backtracking, generate and test or back-jumping. can someone help me in this as I am very new to prolog? Your help will be highly appreciated










share|improve this question









New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I found a code to solve the sudoku puzzle in Prolog using clpfd library.



 :- use_rendering(sudoku).

:- use_module(library(clpfd)).
sudoku(Rows) :-
length(Rows, 9), maplist(same_length(Rows), Rows),
append(Rows, Vs), Vs ins 1..9,
maplist(all_distinct, Rows),
transpose(Rows, Columns),
maplist(all_distinct, Columns),
Rows = [A,B,C,D,E,F,G,H,I],
blocks(A, B, C), blocks(D, E, F), blocks(G, H, I).

blocks(, , ).
blocks([A,B,C|Bs1], [D,E,F|Bs2], [G,H,I|Bs3]) :-
all_distinct([A,B,C,D,E,F,G,H,I]),
blocks(Bs1, Bs2, Bs3).

problem(1, [[_,_,_, _,_,_, _,_,_],
[_,_,_, _,_,3, _,8,5],
[_,_,1, _,2,_, _,_,_],

[_,_,_, 5,_,7, _,_,_],
[_,_,4, _,_,_, 1,_,_],
[_,9,_, _,_,_, _,_,_],

[5,_,_, _,_,_, _,7,3],
[_,_,2, _,1,_, _,_,_],
[_,_,_, _,4,_, _,_,9]]).


I need to do this code with different strategies like backtracking, generate and test or back-jumping. can someone help me in this as I am very new to prolog? Your help will be highly appreciated







prolog sudoku






share|improve this question









New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 9 at 22:40









false

10.9k769140




10.9k769140






New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 9 at 16:19









Akanksha Ahuja

11




11




New contributor




Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Akanksha Ahuja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1




    Welcome to stackoverflow.com. You might want to read the online help, particularly the section regarding how to ask a good question. As it stands, your question will likely be down-voted due to there no show of what you have tried to solve the problem and lack of a more specific question. In other words, don't approach your question as if you are asking others to do your work for you, but explain what you've investigated, what you've tried, and more specifically where you are stuck. Have you researched backtracking, generate and test, etc, to understand them?
    – lurker
    Nov 9 at 16:44













  • 1




    Welcome to stackoverflow.com. You might want to read the online help, particularly the section regarding how to ask a good question. As it stands, your question will likely be down-voted due to there no show of what you have tried to solve the problem and lack of a more specific question. In other words, don't approach your question as if you are asking others to do your work for you, but explain what you've investigated, what you've tried, and more specifically where you are stuck. Have you researched backtracking, generate and test, etc, to understand them?
    – lurker
    Nov 9 at 16:44








1




1




Welcome to stackoverflow.com. You might want to read the online help, particularly the section regarding how to ask a good question. As it stands, your question will likely be down-voted due to there no show of what you have tried to solve the problem and lack of a more specific question. In other words, don't approach your question as if you are asking others to do your work for you, but explain what you've investigated, what you've tried, and more specifically where you are stuck. Have you researched backtracking, generate and test, etc, to understand them?
– lurker
Nov 9 at 16:44





Welcome to stackoverflow.com. You might want to read the online help, particularly the section regarding how to ask a good question. As it stands, your question will likely be down-voted due to there no show of what you have tried to solve the problem and lack of a more specific question. In other words, don't approach your question as if you are asking others to do your work for you, but explain what you've investigated, what you've tried, and more specifically where you are stuck. Have you researched backtracking, generate and test, etc, to understand them?
– lurker
Nov 9 at 16:44


















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Akanksha Ahuja is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229510%2fsudoku-prolog-solver-using-clpfd-library%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Akanksha Ahuja is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Akanksha Ahuja is a new contributor. Be nice, and check out our Code of Conduct.












Akanksha Ahuja is a new contributor. Be nice, and check out our Code of Conduct.











Akanksha Ahuja is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229510%2fsudoku-prolog-solver-using-clpfd-library%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus