The clear way I came up with is this:
If all members of the list are different from each other, then if I ask the prolog to select all the pairs (I,J) , so that I,J are members of the list, and also I is equal to J , then for each element in the list he can find one such A couple that is an element with itself.
Therefore, if we can put all such pairs in a list, then the length of this list should have the same length as the original list.
Here is my prolog code:
all_diff(L) :- findall((I,J), (member(I, L), member(J, L), I == J), List), length(L, SupposedLength), length(List, CheckThis), SupposedLength == CheckThis.
source share