每个清单代表一个客户及其汽车品牌和颜色:
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).更多推荐
发布评论