Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %There are 8 candidates, A, B, C, D, E, F, G, H, for an expedition to the North Pole. Only 6 candidates have to be selected: one biologist, hydrologist, weather forecaster, telegraphist, mechanician and doctor.
- %E and G can carry duties of a biologist,
- %B and F - a hydrologist,
- %F and G - a weather forecaster,
- %C and D - a telegraphist,
- %C and H - a mechanician, and
- %A and D - a doctor.
- %However, the candidates chosen can not share the duties.
- %Find possible candidate groups, if
- %F can only go together with B,
- %D - with H and C,
- %C can not go with G, and
- %A not with B.
- group(A,B,C,D,E,F) :-
- bio(A),
- hydro(B),
- weath(C),
- tel(D),
- mech(E),
- doc(F).
- no_doubles([A,B,C,D,E,F]).
- rules(G),
- bio(e).
- bio(g).
- hydro(b).
- hydro(f).
- weath(f).
- weath(g).
- tel(c).
- tel(d).
- mech(c).
- mech(h).
- doc(a).
- doc(d).
- no_doubles([]).
- no_doubles([A|B]) :-
- not(contains(A,B)),
- no_doubles(B).
- takeout(A,[A|B],B).
- takeout(A,[B|C],[B|D]) :-
- takeout(A,C,D).
- contains(A,[A|_]).
- contains(_,[]) :- false.
- contains(A,[_|C]) :-
- contains(A,C).
- rules(contains(f,G)) :-
- contains(b,G),
- takeout(f,G,NG),
- rules(NG).
- rules(contains(d,G)) :-
- contains(h,G),
- contains(c,G),
- takeout(d,G,NG),
- rules(NG).
- rules(contains(c,G)) :-
- not(contains(g,G)),
- takeout(c,G,NG),
- rules(NG).
- rules(contains(a,G)) :-
- not(contains(b,G)),
- takeout(a,G,NG),
- rules(NG).
- rules(_).
Add Comment
Please, Sign In to add comment