Return the list of users in prolog
Solution 1:
This isn't the prettiest code I've written, but I think it works:
node(1,ana,[nature,cat,dog,sw,csharp]).
node(11,antonio,[cat,nature,car,sport,city]).
node(22,isabel,[nature,test,dog,cat]).
node(23,john,[nature,dog,sw,csharp,city]).
node(24,maria,[nature,e,b,c,d]).
suggest_group(Name, NumberOfUsers, MandatoryTag, ListOfGroup) :-
findall((X,Xs),(node(_,X,Xs),X \== Name,member(MandatoryTag,Xs)),Zs),
(collapse(Zs,(ListOfGroup,_)),length(ListOfGroup,NumberOfUsers);ListOfGroup=[]).
collapse([(U,Ts)],([U],Ts)).
collapse([(U,Ts)|Rs],([U|Us],Xs)) :-
collapse(Rs,(Us,Ws)),
intersection(Ts,Ws,Xs).
?- suggest_group(ana, 3, cat, LGroup).
LGroup = [].
?- suggest_group(ana, 2, cat, LGroup).
LGroup = [antonio, isabel] .