PROLOG PROGRAM : Write a Prolog program for Clothing Fshions using recursion (NO
ID: 3873119 • Letter: P
Question
PROLOG PROGRAM :
Write a Prolog program for Clothing Fshions using recursion (NO ITERATIVE SOLUTIONS) given the below:
------------------------------------------------------------------------
(1)items of clothing are represented by structures with name and 3 parameters: the type (hat, shirt, etc.), the color (blue, green, etc.) and size (some whole number).
Below is given:
wearing( jane, clothing( hat, red, 3)).
wearing( jane, clothing( shirt, blue, 4)).
wearing( bill, clothing( shirt, purple, 6)).
wearing( tom, clothing( hat, red, 10)).
wearing( jill, clothing( shirt, blue, 2)).
wearing( bill, clothing( hat, green, 10)).
------------------------------------------------------------------------
(2) what is a test query to find all the colors that bill is wearing?
------------------------------------------------------------------------
(3) write a rule (and test it - provide screen shot results please) to find facts of who will be pinched on Saint Patricks Day for not wearing green.
------------------------------------------------------------------------
(4) what will prolog resolve for the following query (run program with Prolog trace on)?
?-wearing(Whom, clothing( hat, red, _)).
Explanation / Answer
1. Declaring color of shirts of persons with the help of unit clause in Prolog.
2. Test query for finding total colors that Bill wears
Y - this would generate members of individual color list:
color([red,green,blue,purple]).
getcolor(Y) :- color(List), member(Y,List).
/*
| ?- getcolor(Y).
Y = red ? ;
Y = green ? ;
Y = blue ? ;
Y = purple ? ;
*/
3. Query to find the persons not wearing green
domains
list=green
predicates
findcolor(green,list)
clauses
findcolor(Y,[]):-
write(" This person wearing not green Is Punished").
findcolor(Y,[Y|Tail]):-
write("This person wearing green is not punished").
findcolor(Y,[Y|Tail]):-
findcolor(Y,Tail).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.