home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / pdprolog / colors.pro < prev    next >
Text File  |  1986-05-05  |  2KB  |  46 lines

  1. /* A deduction problem from Dell Official Puzzles December, 1985.
  2.    ProLog program by Tom Sullivan  -  November, 1985
  3.  
  4.    Abby, Barb, & Cora have clothes in  blue, green, purple, red & yellow.
  5.    None wears yellow with red.  Each has a two-piece outfit in two colors.
  6.    Abby is wearing blue.  Barb is wearing yellow but not green.  Cora wears
  7.    green but not blue or purple.  One has on red.  One color is worn by both
  8.    Barb and Cora, while Abby & Barb, between them, have on four different
  9.    colors.  Name the colors each woman is wearing.
  10. */
  11.  
  12. human ([abby,barb,cora]).
  13. hue ([blue,green,purple,red,yellow]).
  14.  
  15. member (X,[X|_]).
  16. member (X,[_|Y]) :- member (X,Y).
  17.  
  18. person (X) :- human (Y), member (X,Y).
  19. color (X) :- hue (Y), member (X,Y).
  20.  
  21. hason (abby,blue).
  22. hason (barb,yellow).
  23. hason (cora,green).
  24.  
  25. notwear (barb,green).
  26. notwear (cora,blue).
  27. notwear (cora,purple).
  28. notwear (X,Y) :- not (X = cora),hason (Z,Y).
  29. notwear (abby,X) :- wears (barb,Z),member (X,Z).
  30. notwear (cora,X) :- wears (abby,Z),member (X,Z).
  31.  
  32. wears (X,([Color1,Color2])) :- person (X), color (Color1), color (Color2),
  33.                                hason (X,Color1),
  34.                                not (notwear (X,Color2)),
  35.                                not (Color1 = Color2),
  36.                                not ((Color1 = red),(Color2 =yellow);
  37.                                 (Color1 = yellow), (Color2 = red)).
  38.  
  39. go :- wears (X,Y),print (X,' wears ',Y).
  40.  
  41. /* to query type >> go.<CR>  */
  42.  
  43.  
  44.  
  45.  
  46.