我想找到一种方法,在一个列表中找到最多重复的元素,如果两个元素重复次数相同。我希望谓词是一个包含这两个元素的列表。我该怎么做?
示例查询和预期答案:
我遇到了与最少重复元素相同的问题。
示例查询和预期答案:
?- maxRepeated([1,3,3,4,2,2],X).
X = [3,2].
% common case: there is one element that is the most repeated
?- maxRepeated([1,3,3,3,3,4,2,2],X).
X = [3].
% all elements repeat the same number of times
?- maxRepeated([1,3,4,2],X).
X = [1,3,4,2].
我遇到了与最少重复元素相同的问题。
[1,3,2,1,3,3,1,4,1]
怎么处理? - lurker