I have written this Prolog program:
max(X,Y,X) :- X>=Y.
max(X,Y,Y) :- X<Y.
min(X,Y,X) :- X<Y.
min(X,Y,Y) :- X>=Y.
minlist([X],X).
minlist([X,Y|Rest],Min) :- minlist([Y|Rest],MinRest), min(X,MinRest,Min).
maxlist([X],X).
maxlist([X,Y|Rest],Max) :- maxlist([Y|Rest],MaxRest), max(X,MaxRest,Max).
How can I make it work with one command i.e minmax([1,2,3]) giving the answer 1 and 3? This instead of using two as I do now?
Thank you!
/L
max(X,Y,X) :- X>=Y.
max(X,Y,Y) :- X<Y.
min(X,Y,X) :- X<Y.
min(X,Y,Y) :- X>=Y.
minlist([X],X).
minlist([X,Y|Rest],Min) :- minlist([Y|Rest],MinRest), min(X,MinRest,Min).
maxlist([X],X).
maxlist([X,Y|Rest],Max) :- maxlist([Y|Rest],MaxRest), max(X,MaxRest,Max).
How can I make it work with one command i.e minmax([1,2,3]) giving the answer 1 and 3? This instead of using two as I do now?
Thank you!
/L