Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- eq(X,X).
- ne(X,X):-!,fail.
- ne(X,_).
- ex(_,[]).
- ex(X,[X|_]):-!,false.
- ex(X,[_|L]):-ex(X,L).
- in(X,[X|L],L).
- in(X,[Y|L],[Y|M]):-in(X,L,M).
- match([],[]).
- match([X|L],Q):-in(X,Q,M),match(L,M).
- suguru([
- [V1_1,V1_2,V1_3,V1_4,V1_5],
- [V2_1,V2_2,V2_3,V2_4,V2_5],
- [V3_1,V3_2,V3_3,V3_4,V3_5],
- [V4_1,V4_2,V4_3,V4_4,V4_5],
- [V5_1,V5_2,V5_3,V5_4,V5_5]]) :-
- eq(V1_1, 1),
- eq(V1_4, 5),
- eq(V3_1, 1),
- eq(V3_3, 2),
- eq(V3_5, 4),
- eq(V5_2, 3),
- match([V5_5], [1]),
- match([V1_2,V1_3,V2_1], [2,3,4]),
- match([V1_5,V2_5,V4_5], [1,2,3]),
- match([V4_4,V5_1,V5_3,V5_4], [1,2,4,5]),
- match([V2_2,V2_3,V3_2,V4_1], [2,3,4,5]),
- match([V2_4,V3_4,V4_2,V4_3], [1,3,4,5]),
- ne(V1_1,V2_2),
- ne(V1_2,V2_2),
- ne(V1_2,V2_3),
- ne(V1_3,V1_4),
- ne(V1_3,V2_2),
- ne(V1_3,V2_3),
- ne(V1_3,V2_4),
- ne(V2_1,V2_2),
- ne(V2_1,V3_2),
- ne(V1_4,V2_3),
- ne(V1_4,V2_4),
- ne(V1_5,V2_4),
- ne(V2_5,V3_4),
- ne(V3_5,V4_4),
- ne(V4_5,V5_4),
- ne(V4_5,V5_5),
- ne(V4_4,V4_5),
- ne(V4_4,V5_5),
- ne(V5_4,V5_5),
- ne(V2_2,V3_3),
- ne(V2_3,V2_4),
- ne(V2_3,V3_3),
- ne(V2_3,V3_4),
- ne(V3_1,V4_2),
- ne(V3_2,V3_3),
- ne(V3_2,V4_2),
- ne(V3_2,V4_3),
- ne(V4_1,V4_2),
- ne(V4_1,V5_2),
- ne(V2_4,V2_5),
- ne(V2_4,V3_5),
- ne(V3_3,V4_4),
- ne(V3_4,V3_5),
- ne(V3_4,V4_4),
- ne(V3_4,V4_5),
- ne(V4_2,V5_2),
- ne(V4_2,V5_3),
- ne(V4_3,V4_4),
- ne(V4_3,V5_2),
- ne(V4_3,V5_3),
- ne(V4_3,V5_4),
- true.
- describe:-write('solving...\n'),
- write('+---+---+---+---+---+\n'),
- write('| 1 | 5 |\n'),
- write('+ +---+---+---+ +\n'),
- write('| | | | |\n'),
- write('+---+ +---+ + +\n'),
- write('| 1 | 2 | 4 |\n'),
- write('+ +---+ +---+ +\n'),
- write('| | | | |\n'),
- write('+---+---+---+ +---+\n'),
- write('| 3 | |\n'),
- write('+---+---+---+---+---+\n'),
- true.
- w([]).
- w([X|L]):-write(X),write('\n'),w(L).
- r:-reconsult(suguru).
- h:-halt.
- x:-describe,time(suguru(L)),w(L).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement