Maybe I should post at Tech board?
I want to find the max element of a list, in Prolog.
Here is my code (see comments)
Any ideas ?Code:maxList([], M). maxList([X|L], M):- M is X, maxList2(L, M). maxList2([], M):-writeln(M). /* HERE I HAVE THE CORRECT RESULT! */ /* But the output is going to remain set at the 1st element of the list, no matter what! */ maxList2([X|L], M):- X > M, M1 is X, maxList2(L, M1). maxList2([X|L], M):- X =< M, maxList2(L, M).![]()



LinkBack URL
About LinkBacks




