Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a MIN/MAX

Status
Not open for further replies.

KMK2009

Programmer
Sep 21, 2009
3
CA
Hello,

Is there ANY way in ProLog to find a min/max for unknown amount of elements?
 
I saw some examples like:
is(A), not (is(B), A > B).
is it there another way?
 
Is there ANY way in ProLog to find a min/max for unknown amount of elements?
I supposed you were speaking of that kind of things :
minmax([10,2,....., 1000,20], Min, Max) ==>
Min = 2
Max = 1000
 
nope, without using [], just simple atomic statement and backtracking logic
 
for simple atomic statement

max(X,Y,X):-X >= Y.
max(X,Y,Y):-X < Y.

And for one list of numbers.

maxLis( [] ).
maxList( [E],E ).
maxList( [E,E2 | T],L ):-maxList( [E2 | T],L1 ),max(L1,E,L).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top