I'm trying to write a Prolog function that given a list returns the element(s) that repeats most times in that list, like:
['a', 'a', 'b', 'c', 'b'] should return ['a', 'b'] ['c', 'a', 'a', 'c', 'b', 'c', 'b'] should return ['c'] etc...
I'm trying to do it with another function (that counts the number of times something exists on a list (countlist), but I'm not getting anywhere. A little help please?
listMax(In, Out) :-
listMax(In, Out, 0).
listMax([H | L], [H | O], Max) :-
countlist(H, [H | L], N),
N > Max,
listMax(L, [H | O], N).
listMax([H | L], O, Max) :-
countlist(H, [H | L], N),
<=(Max, N),
listMax(L, O, Max).
listMax([], [], _Max).
listMax([], _O, _Max).