list - Prolog: won't get the biggest element -


I'm learning prologue but I have some difficulties learning this. I have a query that goes through a list of elements with each element and value and I am trying to get the element with the highest value ...

  highest ( [(D, 1), (C, 1), (B, 2), (A, 1)], X, 0).  

Then in this case should be output (or X ) b My code is as follows:

 < Code> highest ([], _, _). Highest (tail (L, V)) tail), X, Y): - (V> = y -> highest (tail, L, V); highest (tail, x, y))  

Thanks will be appreciated!

Something I had to go with:

  highest (L, Alem): - Supreme (L, [], Allem, 0). Supreme ([], Alem, Alem, _) Highest (Tale, El, Alem, V); Highest (Tail, Kurlem, Alem, Y) (- (V, G, Elam, Y)).  

Highest / 2 just call highest / 4 with current element [] and current value as 0

then adds the current element (Arguments 2 and 3) with the base segment / 4 element of the higher.

The recurring section checks the value of the first element in the input list and calls itself with the tail. L or Kural and V or Y accordingly.


Comments