Re: How can i get the count of each number in a file ?

z_axis <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Organization zsoft
Message-ID <[email protected]>
thanks for your codes. Maybe i can use library(assoc) ?

Regards!

在 Thu, 10 Oct 2013 12:28:04 +0800,Richard A. O'Keefe <[email protected]>  
写道:

> member_counts(List, Member_Counts) :-
> 	    attach_weights(List, List_With_Weights),
> 	    keysort(List_With_Weights, Sorted_List_With_Weights),
> 	    add_weights(Sorted_List_With_Weights, Member_Counts).
> 	attach_weights([], []).
> 	attach_weights([X|Xs], [X-1|Pairs]) :-
> 	    attach_weights(Xs, Pairs).
> 	add_weights([], []).
> 	add_weights([X-W|Pairs], Member_Counts) :-
> 	    add_corresponding_weights(Pairs, X, W, Member_Counts).
> 	add_corresponding_weights([X-W1|Pairs], X, W0, Member_Counts) :- !,
> 	    W2 is W0 + W1,
> 	    add_corresponding_weights(Pairs, X, W2, Member_Counts).
> 	add_corresponding_weights(Pairs, X, W, [X-W|Member_Counts]) :-
> 	    add_corresponding_weights(Pairs, Member_Counts).


-- 
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/

_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.