このディレクトリの索引

#  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).

listmax(In,Out) :-
        setof(A,member(A,In),L1),
        findall([Count,A],(
                    member(A,L1),
                    count(A,In,Count)),
               L2),
        max_1(L2,Max),
        findall(A,member([Max,A],L2),Out).

count(A,[],0).
count(A,[A|R],X) :-
        count(A,R,Y),
        X is Y + 1.
count(A,[_|R],X) :-
        count(A,R,X).

max_1(L,Max) :-
        findall(A,member([A|_],L),L1),
        max(L1,Max).