My task was changed a little. And I need to implement abs and max also in prolog. I need to take list of integer and tell if abs value of max is greater then abs value of min. – M
My code is like this :
ismaxgreater([X],X).
ismaxgreater([X],X):-
maxlist([X],X).
%minlist([X],Y),
%abs([Y],Z),
%com(X,Z).
maxlist([X],X).
maxlist([X,Y |Rest],Max) :-
maxlist([Y | Rest], MaxRest),
max(X,MaxRest,Max).
minlist([X],X).
minlist([X,Y |Rest],Min) :-
maxlist([Y | Rest], MinRest),
max(X,MinRest,Min).
com(Max,Min) :- Max>Min,
write('Max is Bigger Value');
Max<Min,
write('Min is Bigger Value').
max(X,Y,X) :- X>= Y.
max(X,Y,Y) :- X < Y.
min(X,Y,X) :- X =< Y.
min(X,Y,Y) :- X > Y.
abs(X,Y) :- X < 0 -> Y is -X; Y = X.
But I want to enter on Input only like this :
ismaxgreater([1,2,-5,9])
where output should be like :
Max is greater true