I have a fact set as so...
fav_fruit(male, young, apple).
fav_fruit(female, young, bannana).
fav_fruit(male, old, bannana).
fav_fruit(female, old, apple).
fav_fruit(female, young, apple).
I'm need find out if there is any group of (Gender,Age) where there is more the one favorite fruit (the answer for the facts above would be (female,young.)
What I've been trying to figure out is how to use the aggregate
or findall
functions in prolog to return some type of list like....
female, young = 2 (apple, bannana)
male, young = 1 (apple)
male, old = 1 (bannana)
female, old = 1 (apple)
...that way I could just check the total for each member and test whether it it greater then 1.
Any ideas would be greatly appreciated.
How about
The first findall+sort gets a list of classes (Gender/Age). The second findall gets the list of favorite fruits for each class.