prolog

时间:2016-03-15 00:51:26

标签: prolog

我尝试按照这个递增顺序将[1,2,3,3,4,5,5,6,6,7]之类的数字列表排序到另外两个列表UniqueNotUnique,这只是为了找出一个数字是否出现多次列表。 1将进入Unique列表,3,3将进入NotUnique列表。

我已根据建议进行了更改,但我在排序列表的末尾保留了_G1678_G1708,这些是什么?

 ?- removeUni([1,2,3,3,4,5,5,5,6],A,B).
A = [1, 2, 4|_G1678],
B = [3, 3, 5, 5, 5, 6, 6|_G1708].

以下是我的removeUni代码:

removeUni([],[],[]).
removeUni([X],[X],[]).    
removeUni([X1,X2],[X1,X2|Uni],D):-
    X1 < X2,
    !.
removeUni([X1,X2],Uni,[X1,X2|D]):-
    X1 =:= X2,
    !.
    removeUni([X],[X|Uni],D).
removeUni([X1,X2,X3|Q],[X1,X2|Uni],D):-
    X1 < X2,
    X2 < X3,
    removeUni([X3|Q],Uni,D),
    !.
removeUni([X1,X2,X3|Q],[X1|Uni],D):-
    X1 < X2,
    X2 == X3,
    removeUni([X2,X3|Q],Uni,D),
    !.
removeUni([X1,X2,X3|Q],Uni,[X1|D]):-
    X1 == X2,
    X2 == X3,
    removeUni([X2,X3|Q],Uni,D),
    !.
removeUni([X1,X2,X3|Q],Uni,[X1,X2|D]):-
    X1 == X2,
    X2 < X3,
    removeUni([X3|Q],Uni,D),
    !.

0 个答案:

没有答案