Include the following facts at the beginning of a Prolog database:
fruit(orange).
veggie(peas).
junk(chips).
protein(steak).
fiber(cereal).
Now define the following facts and rules.
1. Define rules for the predicate cal(<food>, <number>)
which
gives the <number> of calories in one serving of <food> such as fruit.
Use the following made-up values:
fruits have 50 calories, veggies have 20 calories, junk has 100 calories,
fiber has 100 calories, and protein has 200 calories. For example,
the following query can be used as a test:
?- cal(orange, X).
X= 50
2. Define 1 or more rules for good_breakfast(<list>),
where <list> is a list of food such as [orange, steak]. The predicate
is true iff the <list> contains fiber and fruit. (Hint: use member.)
For example, the following query can be used as a test:
?- good_breakfast([chips, cereal, peas, orange]).
yes
3. Define 1 or more rules for total(<list>, <number>),
which gives the total <number> of calories in the meal described in
<list>. Your rules must work for any valid <list>. (Hint:
use recursion.) For example, the following query can be used as a
test:
?- total([orange, peas, chips], X).
X=170
4. Define 1 or more rules for stay_on_diet(<list>), where
<list> is a list of food. The predicate is true iff the total
calories in <list> is less than 500. (Hint: use your total
predicate.)
For example, the following queries can be used as tests:
?- stay_on_diet([steak, steak, steak]).
no
?- stay_on_diet([orange, steak]).
yes
5. Define 1 or more rules for good_diet(<list>), where <list> is a list of food. The predicate is true iff <list> is a good_breakfast (defined in problem 2), contains a protein food, and satisfies stay_on_diet (defined in problem 4). For example, the following queries can be used as tests:
?- good_diet([orange, chips, chips, cereal,
steak]).
no
?- good_diet([orange, cereal, steak, chips]).
yes
Submission instructions:
Turn in a printout of your implementation of the Prolog predicates
and give me the full AFS pathname (and appropriate access rights) to a
file containing the predicates so that I can test them if need be.
(See the Java assignment for directions on giving access rights).