fork download
  1. count_occ([], []).
  2. count_occ([H|T], R) :-
  3. count_occ(T, Temp),
  4. increment(Temp, H, R).
  5.  
  6. increment([], E, [[E,1]]).
  7. increment([[H,C]|T], H, [[H,CplusOne]|T]) :-
  8. CplusOne is C + 1.
  9. increment([[H,C]|T], E, [[H,C]|R]) :-
  10. H \= E,
  11. increment(T, E, R).
  12.  
  13. :- count_occ([a,b,b,a,c,d,a,b,e,b,d,c], R), writeln(R).
  14.  
Success #stdin #stdout #stderr 0.02s 6160KB
stdin
Standard input is empty
stdout
[[c, 2], [d, 2], [b, 4], [e, 1], [a, 3]]
stderr