比较prolog中超过2个列表的元素,以确定两个元素是否完全相同(Comparing more than 2 lists' elements in prolog to find if exa

编程入门 行业动态 更新时间:2024-10-11 21:20:10
比较prolog中超过2个列表的元素,以确定两个元素是否完全相同(Comparing more than 2 lists' elements in prolog to find if exactly two elements are the same)

每个清单代表一个客户及其汽车品牌和颜色:

customer([_Name,_Surname,_Car,_Color]).

我想知道我是否可以检查超过2个列表,没有客户拥有相同颜色的同一辆车。 因为每个客户的姓名和姓氏都不同,(意味着只有_Car和_Color可以在列表中使用相同的值),我认为一种方法是检查列表中没有完全相同的2个元素。 列表的一个例子是:

customer1([john,brown,vw,black]). customer2([will,smith,audi,green]). customer3([nick,cave,bmw,blue]). customer4([jim,beam,bmw,black]).

在这个例子中,没有相同的品牌和相同的颜色,所以这是真的。

我想象的是:

result:-customer1(X1,Y1,Z1,W1), customer2(X2,Y2,Z2,W2), customer3(X3,Y3,Z3,W3), customer4(X4,Y4,Z4,W4), (check that no Z's AND W's are the same).

这可能吗?

Each list represents a customer and his car brand and colour:

customer([_Name,_Surname,_Car,_Color]).

I would like to know if I can check in more than 2 lists that no customers have the same car of the same color. Because each customer has different name and surname from the others, (meaning that only _Car and _Color can take the same values in lists), I think one way is to check that the lists have not exactly 2 same elements. An example of lists is:

customer1([john,brown,vw,black]). customer2([will,smith,audi,green]). customer3([nick,cave,bmw,blue]). customer4([jim,beam,bmw,black]).

In this example none has the same brand and the same color, so it's true.

What I imagine is something like:

result:-customer1(X1,Y1,Z1,W1), customer2(X2,Y2,Z2,W2), customer3(X3,Y3,Z3,W3), customer4(X4,Y4,Z4,W4), (check that no Z's AND W's are the same).

Is this possible?

最满意答案

此查询将回答具有相同颜色的相同汽车的不同人:

?- customer([Name1,Surname1,Car,Color]), customer([Name2,Surname2,Car,Color]), ( Name1 \= Name2 ; Surname1 \= Surname2).

this query would answer about different persons having the same Car of same Color:

?- customer([Name1,Surname1,Car,Color]), customer([Name2,Surname2,Car,Color]), ( Name1 \= Name2 ; Surname1 \= Surname2).

更多推荐

本文发布于:2023-04-29 02:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   完全相同   两个   列表   prolog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!