このディレクトリの索引

#  Hello, I'm trying to make a prolog function (I know it's not a function
#  but I can't recall it's name) that given a list and a number N
#  returns a list with the elements that repeat at least N times.
#  
#  xpto(['a', 'a', 'a', 'b', 'b', 'c'], Out, 3) should return Out = ['a']
#  
#  xpto(['a', 'a', 'a', 'b', 'b', 'c'], Out, 2) should return Out = ['a', 'b']
#  
#  etc.
#  
#  I currently have:
#  
#  xpto([], _, _).
#  
#  xpto([H | L], O, Num) :-
#      count(H, [H | L], N),
#      N = Num,
#      xpto(L, [H | O], Num).
#  
#  xpto([H | L], O, Num) :-
#      count(H, [H | L], N),
#      N \= Num,
#      xpto(L, O, Num).
#  where in count(A, L, N) N is the number of times A repeats in L, however it doesn't work. I'm pretty sure my algorithm works on paper.
#  
#  Any help is appreciated :)

xpro(L,Out,N) :-
        setof(M,member(M,L),L1),
        findall(A,(
                    member(A,L1),
                    count(member(A,L),Count),
                    Count >= N),
                Out).