tags:

views:

47

answers:

1

Hello SO,

I am writing a PROLOG program in which the variable of interest (Q) refuses to unify. I have gotten around this with a hacky solution (include a write statement). But there has to be a way to make this unify, but for the love of me, I am not able to figure it out.

I'd really appreciate any help. Thanks in advance.

Here is my code (I have annotated wherever I have excluded code for brevity)

:- use_module(library(bounds)).
:- use_module(library(lists)).

solve([17],Q,_,_,_):- write(Q). %this is the hacky workaround
solve(L,Q,1,3,2) :- jump(L,Q,N,1,3,2,R), solve(N,R,S,D,M), member([S|[D|[M|[]]]],[[1, 3, 2], [1, 9, 4], [2, 10, 5] this list contains 76 items - all of which are lists of length 3. I have omitted them here for the sake of brevity]).
% there are about 75 other definitions for solve, all of which are structured exactly the same. The only difference is that the numbers in the input parameters will be different in each definition

jump(L,Q,N,S,D,M,R):- member(S,L), not(member(D,L)), member(M,L), delete(L,S,X), delete(X,M,Y), append(Y,[D],N), append(Q,[[S,D]],R).

cross_sol(Q) :- solve([5,9,10,11,17,24],Q,S,D,M), member([S,D,M], [
I have edited out this list here for the sake of brevity. It is the same list found in the definition of solve
]).

For some reason, Q does not unify. Please help! Thank you!

+1  A: 

The cross_sol/1 predicate seems malformed.

cross_sol(Q) :- solve([5,9,10,11,17,24],[],S,D,M), member([S,D,M], [ I have edited out this list here for the sake of brevity. It is the same list found in the definition of solve ]).

The variable Q is a singleton -- it is not referenced anywhere in the body (unless it is the portion you have suppressed).

Lindsey Spratt
No, Q is not in the part that I have suppressed. However, I did take your answer into account and changed cross_sol(Q) (as indicated in the edit to my above code), but that didn't seem to change anything.
inspectorG4dget
Now I can test your code a little.The cross_sol(Q) query fails.The failure is due to jump([5,9,10,11,17,24], Q, N, 1, 3, 2, R) on the goal 'member(S, L)'. S is 1 and L is [5,...,24]. There is no 1 in L.
Lindsey Spratt