In: Computer Science
• Write a complete prolog with your own facts using the relation: – Like(Person,Food).
• Define the following rule: –
Two persons are friends if they like the same food.
• Now find:
– All people who like more than one food.
– All food liked by two people – All friends
• likes(sarah, pizza).
• likes(sarah, saleeg)
. • likes(sarah, bread)
. • likes(farah, rice).
• likes(rana, burger)
. • likes(rana, saleeg).
Given relation is
likes(Person, Food). it can be read as "Person likes Food".
For example: If the given fact for given relation is "likes(sarah, pizza)." then it means that sarah likes pizza.
Rule for "Two persons are friends if they like the same food." will be
friends(Person1, Person2) :- likes (Person1, Food), likes (Person2, Food).
It means Person1 and Person2 both are friends if Person1 like Food and Person2 likes the same Food.
Given facts are:
In the given facts there are three Person: sarah, farah and rana
and there are 5 types of Food: pizza, saleeg, bread, rice and burger
From the given facts we can say that
– All people who like more than one food: sarah, rana.
– All food liked by two people: saleeg.
– All friends: As sarah and rana have a common food saleeg. So, sarah and rana are friends.
If you're still having any doubt then please feel free to ask in the comment section.