0
我正在編寫一個PROLOG程序,其中感興趣的變量(Q)拒絕統一。我用一個hacky解決方案解決了這個問題(包括一個write
聲明)。但是必須有一種方法來使這種統一,但爲了我的愛,我無法弄清楚。爲什麼'Q'在這個PROLOG程序中不統一
我非常感謝任何幫助。 在此先感謝。
這裏是我的代碼(我已標註的地方我已經排除了簡碼)
:- 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
]).
出於某種原因,Q不統一。請幫忙! 謝謝!
不,Q不在我壓制的部分。但是,我確實考慮了您的答案,並將cross_sol(Q)(如編輯中指示的那樣更改爲我的上面的代碼),但這似乎沒有改變任何內容。 – inspectorG4dget
現在我可以測試你的代碼了。 cross_sol(Q)查詢失敗。 失敗是由於目標'member(S,L)'上的跳躍([5,9,10,11,17,24],Q,N,1,3,2,R)。 S是1並且L是[5,...,24]。 L.中沒有1。 –