Re: Counter of elements in prolog
- From: Peter Van Weert <Peter.VanWeert@xxxxxxxxxxxxxx>
- Date: Tue, 30 Jan 2007 19:46:17 +0100
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
.
- References:
- Re: Counter of elements in prolog
- From: Heuchi
- Re: Counter of elements in prolog
- From: Sied@r
- Re: Counter of elements in prolog
- Prev by Date: Re: Parallel Prolog
- Next by Date: Re: Parallel Prolog
- Previous by thread: Re: Counter of elements in prolog
- Next by thread: Re: Counter of elements in prolog
- Index(es):
Relevant Pages
|
|