[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Counting the solutions....
From: |
Michał Bieliński |
Subject: |
Re: Counting the solutions.... |
Date: |
Fri, 29 Oct 2010 18:38:17 +0200 |
User-agent: |
SquirrelMail/1.4.20 |
gowtham wrote:
> Hi All,
> Bear with this newbie. I come from procedural programming and started to
> learn prolog a week ago. Though, I really appreciate its amazing capacity,
I had a look at your code and tried to execute it without examining it
closely. It complained about undefined flag/3 predicate in count/2. After
commenting it out it ran fine.
> My quaries are getting the solutions but, i have problem in counting the
> solutions.
> count_pcg0(X) :-
Writes _29 here.
> count_pcg(X) :-
Writes _29_29 here. My impression is you are not using GNU Prolog and we
get wildly different results. I suggest another solution.
findall/3 is very useful for collecting solutions.
findall(GOAL, prop(GOAL, is_coding, 'YES'), LIST) will return a LIST of
atoms satisfying query given as second argument to this findall
invocation.
Use this in count_pcg0(X) predicate to simplify it. You'll need to count
elements in list but this allows you to remove duplicates if you wish.
count_pcg(X) is only a little bit trickier. A possible solution is to
combine all conditions into a single predicate.
cond_pcg(X) :-
node(X),
prop(X, is_coding, 'YES'),
prop(X, located_on, 'Lmjchr1').
--
Michał Bieliński