Home > Archive > Prolog > October 2005 > Counting, Highest Value, No Same Output
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Counting, Highest Value, No Same Output
|
|
| justganu@yahoo.com 2005-10-09, 3:56 am |
| hi all... thans for dropping by here... but hope u can help me.... this
is my problem.... in prolog how can we have:
1. counting..... say we wanna count the number of pc type computer from
a given facts:
price(pc,1000.00).
price(pc,2000.00).
price(laptop,3000.00).
price(pc,4000.00).
so, the output(answer) should be 3 that is ther r 3 computers which
type is pc.
2. highest value... say we wanna find a computer with the highest price
from the given facts.... so, the output(answer) should be pc
4000.00......
3. prevent same output..... say we wanna display out who likes to eat
fish... facts:
likes(joe,tuna).
likes(jane,mackerel).
likes(joe,mackerel).
likes(dean,chicken).
likes(jane,finch).
foodtype(tuna,fish).
foodtype(mackerel,fish).
foodtype(chicken,bird).
foodtype(finch,bird).
so, how can i have the correct output without having the same value
more than one....that is:
Who = joe
who = jane
NOT
Who = joe
Who = jane
Who = joe // dont want this cuz it has appeared before.
i realy hope u can help me solving this things....n i preceded with
million thans....
| |
| Roland Illig 2005-10-09, 7:56 am |
| justganu@yahoo.com wrote:
> hi all... thans for dropping by here... but hope u can help me.... this
> is my problem.... in prolog how can we have:
>
> 1. counting..... say we wanna count the number of pc type computer from
> a given facts:
>
> 2. highest value... say we wanna find a computer with the highest price
> from the given facts.... so, the output(answer) should be pc
> 4000.00......
>
> 3. prevent same output..... say we wanna display out who likes to eat
> fish... facts:
This looks perfectly like homework. You won't learn much by copying what
others have written. Do some experiments yourself. If you have written
some code, and it still does not work, ask here. We'll gladly answer
your questions.
Roland
| |
| Bart Demoen 2005-10-09, 7:56 am |
| justganu@yahoo.com wrote:
> hi all... thans for dropping by here... but hope u can help me.... this
> is my problem.... in prolog how can we have:
>
> 1. counting..... say we wanna count the number of pc type computer from
> a given facts:
>
> price(pc,1000.00).
> price(pc,2000.00).
> price(laptop,3000.00).
> price(pc,4000.00).
>
> so, the output(answer) should be 3 that is ther r 3 computers which
> type is pc.
Look in the manual for findall/3.
>
> 2. highest value... say we wanna find a computer with the highest price
> from the given facts.... so, the output(answer) should be pc
> 4000.00......
Look for sort/2 (in combination with findall/3) or alternatively look
for setof/3 (which is a bit harder to understand).
>
> 3. prevent same output..... say we wanna display out who likes to eat
> fish... facts:
>
> likes(joe,tuna).
> likes(jane,mackerel).
> likes(joe,mackerel).
> likes(dean,chicken).
> likes(jane,finch).
>
> foodtype(tuna,fish).
> foodtype(mackerel,fish).
> foodtype(chicken,bird).
> foodtype(finch,bird).
>
> so, how can i have the correct output without having the same value
> more than one....that is:
>
> Who = joe
> who = jane
>
> NOT
>
> Who = joe
> Who = jane
> Who = joe // dont want this cuz it has appeared before.
>
Again findall/3 + sort/2 will help you out, but if you really want to
have the output at the toplevel you describe, you might need tabling or
the dynamic database (assert etc).
Cheers
Bart Demoen
|
|
|
|
|