Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In particular, you are feeding these family members: Alyssa is a vegetarian; she will not eat any dish containing meat. Clara hates vegetables; she will

In particular, you are feeding these family members:

Alyssa is a vegetarian; she will not eat any dish containing meat. Clara hates vegetables; she will not eat any dish containing vegetables. Daniel will eat only organic food. Elena will not eat any desserts. Isaiah, who is lactose-intolerant, will not eat any food containing dairy products. Justin is allergic to peanuts and will not eat any food containing them.

A meal is a list of dishes. Each dish will be specified as a list of six numbers:

[Dish_number, Has_meat?, Has_vegetables?, Organic?, Is_dessert?, Has_dairy?, Has_peanuts?]

The first number, a positive integer between 1 and 100, serves as the name of the dish. The remaining numbers in the list are either 1 or 0, indicating whether the dish has a particular property; 1 indicates that the dish has that property, and 0 indicates that it does not.

For example,

[8, 1, 0, 1, 0, 0, 0] 

means that dish 8 contains meat, does not contain vegetables, is organic, is not a dessert, does not contain dairy, and does not contain peanuts.

Write a Prolog program to solve the problem described above. Define a predicate satisfactory_meal(+Meal) whose parameter is a list of lists of the form [Dish_number, Has_meat?, Has_vegetables?, Organic?, Is_dessert?, Has_dairy?], where the Dish_number is a positive integer and the other list items are 1 or 0. The predicate should succeed if the meal is satisfactory, and fail otherwise.

You may assume that list Meal will be in the correct format when the predicate is called; you do not have to error-check for a non-list or an incorrectly formed list. The events in list Meal are not necessarily sorted by dish numbers or any other order. In your program, you may write and call any additional predicates that are helpful in the computation

satisfactory_meal([ [8, 1, 0, 1, 0, 0, 0], [9, 0, 1, 1, 0, 0, 0], [23, 0, 0, 1, 0, 0, 0], [2, 0, 0, 1, 1, 0, 0], [6, 0, 0, 1, 1, 1, 1] ]) 

should succeed,

satisfactory_meal([ [4, 1, 0, 0, 0, 0, 1], [7, 0, 1, 1, 0, 0, 0], [90, 0, 1, 0, 0, 0, 0], [3, 0, 0, 1, 1, 0, 0] ]) 

should fail,

satisfactory_meal([ ]) 

should fail.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

understand the key issues concerning international assignments

Answered: 1 week ago