Let's say we have this database:
choice(marie, [peru,greece,vietnam]).
choice(jean, [greece,peru,vietnam]).
choice(sasha, [vietnam,peru,greece]).
We want to know the best country based on the list of choice of each person, element 0 in the list is category 3, second category 2, and third category 1, So by asking:
?- where([marie,jean,sasha],Country).
we should get: Country = peru
This is what I have so far but I can't get the value associated with a country to go back up the chain of choice.
where([],Count).
where([Name|L], Count) :-
where(L, Count),
choice(Name,LPref),
calc(LPref,0,0,0,4) .
calc([],P,G,V,1).
calc([H|L],P,G,V,N) :-
N1 is N-1,
calc(L, P,G,V,N1),
pays(H,P,G,V,N1).
pays(H,P,G,V,N) :-
H == 'peru',
P is P+N.
pays(H,P,G,V,N) :-
H == 'greece',
G is G+N.
pays(H,P,G,V,N) :-
H == 'vietnam',
incr(V,N).
incr(I, I).
incr(I, K) :-
J is I + 1,
pays(H,J,G,V,N),
incr(J, K).