Re: Counter of elements in prolog



Sied@r schreef:

I'm getting (A,Y)
(2,2) (2,1) (2,1) (3,2) (3,1) (1,1) (3,1) (_G291,0)

So probably a lot more as you want it to produce...

thanks - yep I think this is much more that I need

is there posibility to filter to only uniq answers ?

D.

Maybe one of the following programs is more what you need (for your homework??)...

% longer
count([A|As], B, Y) :-
count(As, A, X, R),
(
Y is X+1,
B = A
;
count(R, B, Y)
).

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

/*
% shorter
count(L, A, Y) :-
sort(L, S),
member(A, S),
sublist('='(A), L, SL),
length(SL, Y).
*/

Cheers,
Peter
.



Relevant Pages

  • Re: Uniq is not unique ?
    ... uniq command does not filter the repetitive lines. ... I happened to know the source code for uniq and it should filter ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ... Trouble? ...
    (Debian-User)
  • Re: Schlieren Microscopes
    ... Did it give a recipe for the schlieren ... hbarwood@xxxxxxxx schreef: ... > Hi Rene, ...
    (sci.techniques.microscopy)
  • Re: [OT] I give up with the reply-to business already
    ... duplicates via procmail. ... I prefer to filter out the author's email address from my follow-up, ...
    (perl.beginners)
  • Re: Uniq is not unique ?
    ... will need to sort first then pipe to uniq (not a good solution for ... I sometimes need to filter repeated lines that are not consecutive, ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Need help setting IP address on DS20 (VMS 7.3)
    ... Z schreef: ... network switch uses MAC address filtering. ... a filter table, allowing access, but the new address must be added to ...
    (comp.os.vms)