Guest User

Untitled

a guest
Nov 26th, 2022
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. p(450). p(525). p(600).
  2. p(675). p(750). p(825). p(900).
  3. d(belhino). d(eldang). d(mechania).
  4. d(motomiya). d(suzutake). d(werril). d(zarobit).
  5. r(100). r(150). r(250).
  6. r(350). r(475). r(650). r(1000).
  7. f(10). f(15). f(20).
  8. f(25). f(30). f(40). f(60).
  9.  
  10. myall_unique(List) :- all_unique(List, []).
  11.  
  12. all_unique([], _).
  13. all_unique([X|Xs], Seen) :-
  14. not_in(Seen, X),
  15. all_unique(Xs, [X|Seen]).
  16.  
  17. not_in([], _).
  18. not_in([X|Xs], Y) :-
  19. dif(X, Y),
  20. not_in(Xs, Y).
  21.  
  22. select4([],[],[],[],[]).
  23. select4(Ps,Ds,Rs,Fs,[[P,D,R,F]|Sol0]) :-
  24. select(P,Ps,Ps0),
  25. select(D,Ds,Ds0),
  26. select(R,Rs,Rs0),
  27. select(F,Fs,Fs0),
  28. select4(Ps0,Ds0,Rs0,Fs0,Sol0).
  29.  
  30. clue1(Sol) :-
  31. freeze(Sol,(
  32. member([825,_,R1,F1],Sol),
  33. member([P2,_,250,F2],Sol),
  34. member([P3,_,R3,20],Sol),
  35. member([P4,_,475,F4],Sol),
  36. member([P5,_,150,F5],Sol),
  37. member([P6,_,350,F6],Sol),
  38. member([P7,_,R7,40],Sol),
  39. when((
  40. ground(R1),ground(F1),
  41. ground(P2),ground(F2),
  42. ground(P3),ground(R3),
  43. ground(P4),ground(F4),
  44. ground(P5),ground(F5),
  45. ground(P6),ground(F6),
  46. ground(P7),ground(R7)),(
  47. myall_unique([P2,P3,P4,P5,P6,P7,825]),
  48. myall_unique([R1,R3,R7,250,475,150,350]),
  49. myall_unique([F1,F2,F4,F5,F6,20,40])
  50. ))
  51. )).
  52.  
  53. clue2(Sol) :-
  54. freeze(Sol,(
  55. member([P1,_,650,_],Sol),
  56. member([P2,mechania,_,_],Sol),
  57. when((ground(P1),ground(P2)),(P1 > P2))
  58. )).
  59.  
  60. clue3(Sol) :-
  61. freeze(Sol,(
  62. member([P,D,_,60],Sol),
  63. when((ground(P),ground(D)),(P == 750 ; D == eldang))
  64. )).
  65.  
  66. clue4(Sol) :-
  67. freeze(Sol,(
  68. (member([900,_,350,_],Sol),
  69. member([_,belhino,_,25],Sol))
  70. ;
  71. (member([900,belhino,_,_],Sol),
  72. member([_,_,350,25],Sol))
  73. )).
  74.  
  75. clue5(Sol) :-
  76. freeze(Sol,(
  77. (member([900,_,_,20],Sol),
  78. member([_,zarobit,150,_],Sol))
  79. ;
  80. (member([900,_,150,_],Sol),
  81. member([_,zarobit,_,20],Sol))
  82. )).
  83.  
  84. clue6(Sol) :-
  85. freeze(Sol,(
  86. (member([_,_,100,40],Sol),
  87. member([825,_,_,15],Sol))
  88. ;
  89. (member([825,_,_,40],Sol),
  90. member([_,_,100,15],Sol))
  91. )).
  92.  
  93. solve(Sol) :-
  94. findall(P,p(P),Ps),
  95. findall(D,d(D),Ds),
  96. findall(R,r(R),Rs),
  97. findall(F,f(F),Fs),
  98.  
  99. clue1(Sol),
  100. clue2(Sol),
  101. clue3(Sol),
  102. clue4(Sol),
  103. clue5(Sol),
  104. clue6(Sol),
  105.  
  106. select4(Ps,Ds,Rs,Fs,Sol).
Advertisement
Add Comment
Please, Sign In to add comment