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
prolog sudoku
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.
add a comment |
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
prolog sudoku
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
add a comment |
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
prolog sudoku
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
prolog sudoku
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.
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
add a comment |
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
add a comment |
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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