Advertisement
Guest User

regrette

a guest
Apr 23rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 2.35 KB | None | 0 0
  1. :- use_rendering(table,
  2.          [header(h('Owner', 'Pet', 'Cigarette', 'Drink', 'Color'))]).
  3.  
  4. zebra_owner(Owner) :-
  5.     houses(Hs),
  6.     member(h(Owner,zebra,_,_,_), Hs).
  7.  
  8. water_drinker(Drinker) :-
  9.     houses(Hs),
  10.     member(h(Drinker,_,_,water,_), Hs).
  11.  
  12.  
  13. houses(Hs) :-
  14.     % each house in the list Hs of houses is represented as:
  15.     %      h(Nationality, Pet, Cigarette, Drink, Color)
  16. /* Houses logical puzzle: who owns the zebra and who drinks water?
  17.  
  18.      1) Five colored houses in a row, each with an owner, a pet, cigarettes, and a drink.
  19.      2) The English lives in the red house.
  20.      3) The Spanish has a dog.
  21.      4) They drink coffee in the green house.
  22.      5) The Ukrainian drinks tea.
  23.      6) The green house is next to the white house.
  24.      7) The Winston smoker has a serpent.
  25.      8) In the yellow house they smoke Kool.
  26.      9) In the middle house they drink milk.
  27.     10) The Norwegian lives in the first house from the left.
  28.     11) The Chesterfield smoker lives near the man with the fox.
  29.     12) In the house near the house with the horse they smoke Kool.
  30.     13) The Lucky Strike smoker drinks juice.
  31.     14) The Japanese smokes Kent.
  32.     15) The Norwegian lives near the blue house.
  33.  
  34. Who owns the zebra and who drinks water?
  35. */
  36.     length(Hs, 5),                                            %  1
  37.     member(h(english,_,_,_,red), Hs),                         %  2
  38.     member(h(spanish,dog,_,_,_), Hs),                         %  3
  39.     member(h(_,_,_,coffee,green), Hs),                        %  4
  40.     member(h(ukrainian,_,_,tea,_), Hs),                       %  5
  41.     next(h(_,_,_,_,green), h(_,_,_,_,white), Hs),             %  6
  42.     member(h(_,snake,winston,_,_), Hs),                       %  7
  43.     member(h(_,_,kool,_,yellow), Hs),                         %  8
  44.     Hs = [_,_,h(_,_,_,milk,_),_,_],                           %  9
  45.     Hs = [h(norwegian,_,_,_,_)|_],                            % 10
  46.     next(h(_,fox,_,_,_), h(_,_,chesterfield,_,_), Hs),        % 11
  47.     next(h(_,_,kool,_,_), h(_,horse,_,_,_), Hs),              % 12
  48.     member(h(_,_,lucky,juice,_), Hs),                         % 13
  49.     member(h(japonese,_,kent,_,_), Hs),                       % 14
  50.     next(h(norwegian,_,_,_,_), h(_,_,_,_,blue), Hs),          % 15
  51.     member(h(_,_,_,water,_), Hs),       % one of them drinks water
  52.     member(h(_,zebra,_,_,_), Hs).       % one of them owns a zebra
  53.  
  54. next(A, B, Ls) :- append(_, [A,B|_], Ls).
  55. next(A, B, Ls) :- append(_, [B,A|_], Ls).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement