I need your help in solving the following problem:
There're 3 girls (Ann,Susan,Alice) who need to choose what color shoes and dress to wear. There're 3 possible colors for shoes and dresses: white, blue and green.
Main conditions:
My code satisfies only 2 conditions; I'm kinda having hard times meeting conditions on the same color for Susan and whereas other girls need to have different color garments.
Here's what I come up with:
PREDICATES
girl(symbol)
shoes(symbol,symbol)
skirt(symbol,symbol)
hates(symbol,symbol)
will_wear(symbol, symbol, symbol)
CLAUSES
will_wear(X,Y,Z):-
girl(X),
shoes(X,Y),
skirt(X,Z),
not(hates(X,Y)),
not(hates(X,Z)).
girl(ann).
girl(susan).
girl(alice).
hates(ann,white).
skirt(_,white).
skirt(_,blue).
skirt(_,green).
shoes(alice,white).
shoes(_,blue).
shoes(_,green).
GOAL
will_wear(Name,Shoes,Dress).
Code above works fine, but gives too many solutions. Plus, I couldn't come up with any logical solution for the condition for Susan to wear shoes and dress of same color.
Thanks.
If I understand the conditions correctly, they're not what Shurane answered.
This will make sure that a girl wears a dress and shoes with the same colour:
same_color(Girl) :-
shoes(Girl, Color),
dress(Girl, Color).
I'll leave the different colour one as an exercise, but hint that to say two things are not the same you say A \= B
. Please leave a comment if you have a hard time with different_color - and tell me what you've tried.