Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a rule \"bookReader\" using Prolog. Someone is a \"bookReader\" if the

ID: 3838299 • Letter: I

Question

Implement a rule "bookReader" using Prolog.

Someone is a "bookReader" if they read AT LEAST THREE books in a year.
Assume that the only types of facts available are:

"enjoys" facts of the form enjoys(p,a), meaning that person p enjoys object a.
"objectKind" facts of the form objectKind(a,b), meaning that object named a is of type b.

For example:

enjoys(mary,mrToad) means that a person named "mary" enjoys an object named "mrToad".
objectKind(mrToad,book) means that the object named "mrToad" is a book.
objectKind(joconda,painting) means that the object named "joconda" is a painting.
bookReader(mary) would be true if mary enjoys three different objects that were books.

Explanation / Answer

This is a bit tricky one, as we have only two facts and we have to implement AT LEAST THREE in a rule.

Let's get on with it:

There are two parts to the problem, first is implementing "at least three" and second one is using only two facts. Using only two facts actually limits our options and we can't openly declare something. If we go on to write three cases inside out logic that will map to three exact variables in our logic which isn't affordable.

A simpler method would be using list, example:

bookReader(X):-
enjoys(X,[ab,bb,cc | _]),
objectKind([ab,bb,cc | _],book).

This not only erases the need of one extra variable in the logic but also deals with our at "least three case." I hope this satisfies you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote