Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count the number of results. 1

Status
Not open for further replies.

Tenes

IS-IT--Management
Mar 26, 2010
6
0
0
GR
Hello,

Suppose we have this example (my real problem has 45 regions here is only 7):

%Coloring Australia
coloring(Wa,Nt,Sa,Ql,Nsw,V,T):-


%Country borders relation to other Countries
different(Wa,Nt),
different(Wa,Sa),
different(Nt,Wa),
different(Nt,Sa),
different(Nt,Ql),
different(Sa,Wa),
different(Sa,Nt),
different(Sa,Ql),
different(Sa,Nsw),
different(Sa,V),
different(Ql,Nt),
different(Ql,Sa),
different(Ql,Nsw),
different(Nsw,Ql),
different(Nsw,Sa),
different(Nsw,V),
different(V,T).
%different(T,V).


%Color relation to other Colors
different(yellow,blue).
different(blue,yellow).
different(yellow,red).
different(red,yellow).
different(blue,red).
different(red,blue).

I want to count how many different results the query
coloring(Wa,Nt,Sa,Ql,Nsw,V,T). will give.

Thanks in advance
 
You can use setof/3 to get the list of all the different solutions, then use length/2 to get the number of these solutions.
 
Can you give me an example?

I only need a counter with the results (in this example is 12).

 
try
Code:
setof([Wa,Nt,Sa,Ql,Nsw,V,T], coloring(Wa,Nt,Sa,Ql,Nsw,V,T), L), length(L, N).
 
you are the best joel thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top