Skip to content

Instantly share code, notes, and snippets.

@caotic123
Created April 2, 2024 02:20
Show Gist options
  • Save caotic123/f4394771d88ef4ec7fd7f0780029eaf8 to your computer and use it in GitHub Desktop.
Save caotic123/f4394771d88ef4ec7fd7f0780029eaf8 to your computer and use it in GitHub Desktop.
A matching between guy and girls party exercise
willing_to_kiss([], _, __) :- fail.
willing_to_kiss([[P, PLK, _] | T], X, P2) :- (P = X, member(P2, PLK)); willing_to_kiss(T, X, P2).
is_not_in_black_list(K, X, P2) :- member([X, _, BL], K), \+ member(P2, BL).
is_friend(E, P, H) :- (member([P, H], E); member([H, P], E)).
is_match(VM, _, M, F) :- willing_to_kiss(VM, M, F).
might_kiss([VM, _], [VG, __], M, F) :- is_match(VM, VG, M, F).
might_kiss([VM, EM], [VG, EF], M, F) :-
is_not_in_black_list(VM, M, F),
is_friend(EM, M, M1),
(is_match(VM, VG, M1, F); (is_friend(EF, F, F1), is_match(VM, VG, M, F1))).
man_graphs([[
["Joao", ["Elisa", "Monica"], ["Samanta"]],
["Cristiano", ["Samanta", "Leticia"], ["Monica"]],
["Marcelo", ["Elisa"], ["Leticia", "Monica"]],
["Paulo", ["Bianca"], ["Elisa", "Samanta"]],
["Sandro", ["Samanta", "Monica", "Elisa"], ["Bianca", "Leticia"]]],
[["Joao", "Marcelo"],
["Cristiano", "Marcelo"],
["Paulo", "Marcelo"],
["Sandro", "Paulo"],
["Cristano", "Sandro"]]]).
girls_graphs([[
["Bianca", ["Sandro", "Marcelo"], ["Joao"]],
["Monica", ["Paulo"], ["Sandro", "Cristiano"]],
["Elisa", ["Joao", "Cristiano"], ["Paulo", "Marcelo"]],
["Leticia", [], ["Paulo", "Marcelo"]],
["Samanta", ["Joao", "Sandro", "Marcelo"], ["Cristiano"]]],
[["Bianca", "Elisa"],
["Samanta", "Elisa"],
["Leticia", "Samanta"],
["Leticia", "Bianca"],
["Monica", "Samanta"],
["Monica", "Bianca"]]]).
get_persons([], []).
get_persons([[P, _, _] | T], [H | X]) :- H = P, get_persons(T, X).
test1(P, P2) :- man_graphs(L), girls_graphs(L2), might_kiss(L, L2, P, P2).
test2(P, P2) :- man_graphs(L), girls_graphs(L2), might_kiss(L2, L, P, P2).
guess_men(P, X) :- man_graphs(L), girls_graphs(L2), L2 = [VM, _], get_persons(VM, Y),
include(might_kiss(L, L2, P), Y, X).
guess_girls(P, X) :- man_graphs(L), girls_graphs(L2), L = [VF, _], get_persons(VF, Y),
include(might_kiss(L2, L, P), Y, X).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment