Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 如果列表L中的每个项在列表U中恰好出现一次,则谓词成功_List_Prolog_Unique - Fatal编程技术网

List 如果列表L中的每个项在列表U中恰好出现一次,则谓词成功

List 如果列表L中的每个项在列表U中恰好出现一次,则谓词成功,list,prolog,unique,List,Prolog,Unique,我需要Prolog方面的帮助 如果列表L中的每个项目在列表U中恰好出现一次,则在Prolog中编写一个谓词,该谓词将成功 unique(L,U). 完成此任务的多种方法之一(可能不是本任务的解决方法): 让我们试试看: ?- unique([a, b], [a, b, c]). true. ?- unique([a, b], [a, b, c, c]). true. ?- unique([a, b], [a, a, b, c, c]). false. ?- unique([b, a, c

我需要Prolog方面的帮助

如果列表
L
中的每个项目在列表
U
中恰好出现一次,则在Prolog中编写一个谓词,该谓词将成功

unique(L,U).
完成此任务的多种方法之一(可能不是本任务的解决方法):

让我们试试看:

?- unique([a, b], [a, b, c]).
true.

?- unique([a, b], [a, b, c, c]).
true.

?- unique([a, b], [a, a, b, c, c]).
false.

?- unique([b, a, c], [a, b, c, c]).
false.

?- unique([b, a, c], [a, b, c, e]).
true.

在SWI Prolog和ECLiPSe CLP中测试。

请展示您的努力。你知道select/3等吗?如果列表L本身包含重复项怎么办?换句话说,什么应该是唯一的([a,b,a],[a,b,c,a])。应该是什么?是的!?-唯一([a,b,a],[a,b,c,a])。这是正确的。此外,
唯一([a,a,c],[a,b,c,d,d])?
也成功了!:)
?- unique([a, b], [a, b, c]).
true.

?- unique([a, b], [a, b, c, c]).
true.

?- unique([a, b], [a, a, b, c, c]).
false.

?- unique([b, a, c], [a, b, c, c]).
false.

?- unique([b, a, c], [a, b, c, e]).
true.