I have some facts like:
motherboard('name', price, 'price range', score).
I need to take the best motherboard by score, so I guess I should use findall but I'm not understanding how to order by score(desc order) and take the first! Could you help me please?
EDIT - @user27815 solution:
motherboard('Gigabyte B360M Aourus Gaming 3', 86, 'low_range', 3).
motherboard('MSI B350M Mortar', 93, 'low_range', 4).
motherboard('ASUS ROG Strix B350\u002DF', 114, 'middle_range', 6).
motherboard('MSI Z370 Tomahawk', 139, 'middle_range', 7).
motherboard('Gigabyte Aorus AX370 Gaming K7', 169, 'high_range', 8).
setof(Score-Nome,motherboard(Nome, Price,Price_range, Score),Pairs), sort(1,@>,Pairs,Sorted),
write(Pairs),
nl,
write(Sorted).
The result is: [3-Gigabyte B360M Aourus Gaming 3] for both Pairs and Sorted, it ends withoud dot and I can press ; to have more solutions, why is it not printing them all together? And anyway the order is the same for pairs and sorted
@PauloMoura solution- With the same data of the previous solution: setof(Score-Nome,motherboard(Nome, Price, Price_range, Score),Pairs), last(Pairs, BestMotherboard), write(BestMotherboard).
I get this:
?- start.
3-Gigabyte B360M Aourus Gaming 3
true ;
4-MSI B350M Mortar
true ;
6-ASUS ROG Strix B350-F
true ;
7-MSI Z370 Tomahawk
true ;
8-Gigabyte Aorus AX370 Gaming K7
true.
setof(Score-Nome,Price^Price_range^motherboard(Nome, Price,Price_range, Score),Pairs), sort(1,@>,Pairs,Sorted), write(Pairs), nl, write(Sorted).So that the Price and Price range are ignored in the setof call. - user27815setof/3second argument that you want to ignore. That will give you a single solution. - Paulo Moura