Sep 21, 2009 #1 KMK2009 Programmer Sep 21, 2009 3 CA Hello, Is there ANY way in ProLog to find a min/max for unknown amount of elements?
Sep 22, 2009 Thread starter #3 KMK2009 Programmer Sep 21, 2009 3 CA I saw some examples like: is(A), not (is(B), A > B). is it there another way? Upvote 0 Downvote
Sep 23, 2009 #4 joel76 Programmer Aug 31, 2008 295 FR Is there ANY way in ProLog to find a min/max for unknown amount of elements? Click to expand... I supposed you were speaking of that kind of things : minmax([10,2,....., 1000,20], Min, Max) ==> Min = 2 Max = 1000 Upvote 0 Downvote
Is there ANY way in ProLog to find a min/max for unknown amount of elements? Click to expand... I supposed you were speaking of that kind of things : minmax([10,2,....., 1000,20], Min, Max) ==> Min = 2 Max = 1000
Sep 23, 2009 Thread starter #5 KMK2009 Programmer Sep 21, 2009 3 CA nope, without using [], just simple atomic statement and backtracking logic Upvote 0 Downvote
Dec 10, 2009 #6 nn987 Programmer Feb 4, 2006 37 GB 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). Upvote 0 Downvote
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).