I known prolog doesn't return values but i need to update the value of some variable and get it in console with this procedure:
max(A,B,C) :- (A>B -> C is A ; C is B).
maxAltura([],RES).
maxAltura([c(X,Y)|[]],RES) :- max(RES,Y, SUM).
maxAltura([c(X,Y)|R1],RES) :- RES>Y, maxAltura(R1,RES).
maxAltura([c(X,Y)|R1],RES) :- RES<Y, maxAltura(R1,Y).
maxAltura([c(X,Y)|R1],RES) :- RES=:=Y, maxAltura(R1,Y).
It just takes a list of tuples and gives the max value of second element of that tupes.
This is my output
maxAltura([c(1,8),c(5,0),c(6,4),c(10,0),c(11,10),c(12,0)],0).
Call: (7) maxAltura([c(1, 8), c(5, 0), c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 0) ? creep
Call: (8) 0>8 ? creep
Fail: (8) 0>8 ? creep
Redo: (7) maxAltura([c(1, 8), c(5, 0), c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 0) ? creep
Call: (8) 0<8 ? creep
Exit: (8) 0<8 ? creep
Call: (8) maxAltura([c(5, 0), c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 8) ? creep
Call: (9) 8>0 ? creep
Exit: (9) 8>0 ? creep
Call: (9) maxAltura([c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 8) ? creep
Call: (10) 8>4 ? creep
Exit: (10) 8>4 ? creep
Call: (10) maxAltura([c(10, 0), c(11, 10), c(12, 0)], 8) ? creep
Call: (11) 8>0 ? creep
Exit: (11) 8>0 ? creep
Call: (11) maxAltura([c(11, 10), c(12, 0)], 8) ? creep
Call: (12) 8>10 ? creep
Fail: (12) 8>10 ? creep
Redo: (11) maxAltura([c(11, 10), c(12, 0)], 8) ? creep
Call: (12) 8<10 ? creep
Exit: (12) 8<10 ? creep
Call: (12) maxAltura([c(12, 0)], 10) ? creep
Call: (13) max(10, 0, _G4361) ? creep
Call: (14) 10>0 ? creep
Exit: (14) 10>0 ? creep
Call: (14) _G4359 is 10 ? creep
Exit: (14) 10 is 10 ? creep
Exit: (13) max(10, 0, 10) ? creep
Exit: (12) maxAltura([c(12, 0)], 10) ? creep
Exit: (11) maxAltura([c(11, 10), c(12, 0)], 8) ? creep
Exit: (10) maxAltura([c(10, 0), c(11, 10), c(12, 0)], 8) ? creep
Exit: (9) maxAltura([c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 8) ? creep
Exit: (8) maxAltura([c(5, 0), c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 8) ? creep
Exit: (7) maxAltura([c(1, 8), c(5, 0), c(6, 4), c(10, 0), c(11, 10), c(12, 0)], 0) ? creep
true .
As you can see it keeps 10 as max value, witch it's correct by i need something like MAX=10. Why just gives me true?