Exactly one pair in the Prolog list
2 answers
Sorting the list with sort/2
. It removes duplicates, so if the sorted list is exactly one short, you have exactly one pair.
one_duplicate(L) :-
sort(L, Sorted),
length(L, Len),
length(Sorted, SortedLen),
Len =:= SortedLen + 1.
Finding a double pair is another question.
+5
user1812457
source
to share