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

PROLOG !!! needs to be compiled as a *.pl file!!!! A premium pizza is comprised

ID: 3777767 • Letter: P

Question

PROLOG !!!

needs to be compiled as a *.pl file!!!!

A premium pizza is comprised of exactly 40 ounces of toppings. The available toppings are listed below with their corresponding weight (in ounces). There can be multiple entries of each topping, as long as the total weight is equal to 40 ounces.

For example, a pizza can contain 1 topping of pepperoni, 2 toppings of sausage, 1 topping of bacon, and 2 toppings of onion : 1*4 + 2*10 + 1*6 + 2*5 = 40 (ounces)

         A pizza cannot contain 7 toppings of bacon : 7 * 6 = 42 > 40

            A pizza cannot contain only 3 toppings of sausage : 3*10 = 30 < 40

2.1    Define a rule pizza(P, S, B, O, M) to find out how many of each topping can be contained on a pizza, where P, S, B, O, and M are the weight (in ounces) of the Pepperoni, Sausage, Bacon, Onion, and Mushroom toppings respectively.   

2.2    Use your pizza rule to find all possible outputs to the following question (goal).   

| ?- pizza(1, S, 1, O, M). Put all answers of the question in a comment in the file.

2.3    Use your pizza rule to find all possible outputs to the following question (goal).

| ?- pizza(P, S, B, O, 1). Put all answers of the question in a comment in the file.

TOPPING Weight(ounces) Pepperoni 4 Sausage 10 Bacon 6 Onion 5 Mushroom 7

Explanation / Answer

Since a premium pizza is comprised of exactly 40 ounces of toppings. The maximum of each topping which can be used is as follows:
For Pepperoni: Since weight is 4 ounces. So, 10 toppings of pepperoni can be used (4*10=40)
For Sausage: Since weight is 10 ounces. So, 4 toppings of sausage can be used (10*4=40)
For Bacon: Since weight is 6 ounces. So, 6 toppings of bacon can be used (6*6=36), cannot use 7 topping of Bacon as (6*7 = 42)
For Onion: Since weight is 5 ounces. So, 9 toppings of onion can be used (5*8=40)
For Mushroom: Since weight is 7 ounces. So, 5 toppings of mushroom can be used (7*5=35), cannot use 6 topping of Mushroom as (7*6 = 42)

pizza(P,S,B,O,M) % defining a rule
member(P,[0,1,2,3,4,5,6,7,8,9,10]), % at max 10 pepperoni can be used, also P can be true if value is 0 to 10
member(S,[0,1,2,3,4]), % at max 4 sausage can be used
member(B,[0,1,2,3,4,5,6]), % at max 6 bacon can be used
member(O,[0,1,2,3,4,5,6,7,8]), % at max 8 onion can be used
member(M,[0,1,2,3,4,5]), % at max 5 mushroom can be used
TotalWeight is P*4 + S*10 + B*6 + O*5 + M*7, % for summation of weight
TotalWeight =:= 40. % for checking 40 ounces of weight

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