fork(8) download
  1. houses([
  2. house(first, _, _ ),
  3. house(second, _, _ ),
  4. house(third, _, _ ),
  5. house(forth, _, _ )
  6. ]).
  7.  
  8. left_of(A, B, [A, B | _]).
  9. left_of(A, B, [_ | Y]) :- left_of(A, B, Y).
  10.  
  11. right_of(A, B, [B, A | _]).
  12. right_of(A, B, [_ | Y]) :- right_of(A, B, Y).
  13.  
  14. next_to(A, B, [A, B | _]).
  15. next_to(A, B, [B, A | _]).
  16. next_to(A, B, [_ | Y]) :- next_to(A, B, Y).
  17.  
  18. mymember(X, [X|_]).
  19. mymember(X, [_|Y]) :- mymember(X, Y).
  20.  
  21. not_in(_,[]).
  22. not_in(X,[X|_]):-!,fail.
  23. not_in(X,[_|A]):-not_in(X,A).
  24.  
  25. not_trainer(H):-mymember(house(_,roman,hunter),H).
  26. not_trainer(H):-mymember(house(_,roman,doctor),H).
  27. not_trainer(H):-mymember(house(_,roman,painter),H).
  28. not_trainer(H):-mymember(house(_,roman,trainer),H),!,fail.
  29.  
  30. print_houses([]).
  31. print_houses([A|B]) :-
  32. write(A), nl,
  33. print_houses(B).
  34.  
  35. false(X):-X,!,fail.
  36. false(_).
  37.  
  38. solve(H):-houses(H),
  39. next_to(house(_,_,painter),
  40. house(_,_,trainer),H),
  41.  
  42. next_to(house(_,_,doctor),
  43. house(_,_,painter),H),
  44.  
  45. left_of(house(_,_,hunter),
  46. house(_,_,doctor),H),
  47.  
  48. false(next_to(house(_,_,trainer),
  49. house(_,_,hunter),H)),
  50.  
  51. right_of(house(_,_,painter),
  52. house(_,semen,_),H),
  53.  
  54. next_to(house(_,semen,_),
  55. house(_,nikolay,_),H),
  56.  
  57. false(next_to(house(_,artur,_),
  58. house(_,roman,_),H
  59. )),
  60.  
  61. not_trainer(H),
  62.  
  63. mymember(house(_,roman,_), H),
  64. mymember(house(_,artur,_), H),
  65. mymember(house(_,semen,_), H),
  66. mymember(house(_,nikolay,_), H),
  67.  
  68. print_houses(H).
  69.  
  70. :-solve(_).
Success #stdin #stdout 0.02s 6204KB
stdin
Standard input is empty
stdout
house(first, roman, hunter)
house(second, semen, doctor)
house(third, nikolay, painter)
house(forth, artur, trainer)