我有PROLOG非常奇怪的问题。我以前也使用过它,但它已经有一段时间,我很生疏。我有一个列表变量,我需要确保他们都不是一样的。

我曾尝试:

use_module(library(bounds)). all_different(A, B, C, D, 6, 8).

然而,当我尝试,我得到一个错误,指出all_different / 6是不确定的。

我如何去解决这个问题?是否有任何库函数,我可以直接调用这个?

我非常卡住,将不胜感激任何帮助。

预先感谢。

solve([
    [A, 6, 1],

    [B, 5, C, 2, D, E, F, G, 6],

    [6, H, I, 5, J, K, 2, L, 3],

    [5, M, 6, N, O, 4, P, Q, 5],

    [4, R, S, T, U, 6, V, 4, W],

    [2, 0, X]
  ]) :-
     all_different([A,6,1,2,D,E]),
     all_different([B,5,C,6,H,I]),
     all_different([C,2,D,I,5,J]),
     all_different([D,E,F,J,K,2]),
     all_different([F,G,6,2,L,3]),
     all_different([H,I,5,M,6,N]),
     all_different([5,J,K,N,O,4]),
     all_different([K,2,L,4,P,Q]),
     all_different([5,M,6,4,R,S]),
     all_different([6,N,O,S,T,U]),
     all_different([O,4,P,U,6,V]),
     all_different([P,Q,5,V,4,W]),
     all_different([T,U,6,2,1,X]),

     A<7, A>0,       B<7, B>0,       C<7, C>0,       D<7, D>0,
     E<7, E>0,       F<7, F>0,       G<7, G>0,       H<7, H>0,
     I<7, I>0,       J<7, J>0,       K<7, K>0,       L<7, L>0,
     M<7, M>0,       N<7, N>0,       O<7, O>0,       P<7, P>0,
     Q<7, Q>0,       R<7, R>0,       S<7, S>0,       T<7, T>0,
     U<7, U>0,       V<7, V>0,       W<7, W>0,       X<7, X>0.
有帮助吗?

解决方案

all_different([A,B,C,D,6,8]).

我相信只有一个列表可以传递到all_different。

其他提示

我想这> / 2和

        ?- all_different([X,Y]), 0 #< X, X #< 3, 1 #< Y, Y #< 4, indomain(X), indomain(Y). 
        X = 1,
        Y = 2 ;
        X = 1,
        Y = 3 ;
        X = 2,
        Y = 3.

P.S。 indomain / 1相同的库的产率应用的约束之内的所有可行值。

序言的Eclipse的“IC”约束库提供了谓词AllDifferent属性/ 1,这需要一个列表变量作为它的参数,例如,alldifferent([X,Y])并计算你在找什么。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top