Max

Description

Finding the maximum of a list of integers.

Source: The Art of Prolog

Download

Program source code: max.pl

Listing

/*
   maxlist(Xs,N) :- N is the maximum of the list of integers Xs.
*/
     maxlist([X|Xs],M) :- maxlist(Xs,X,M).
 
     maxlist([X|Xs],Y,M) :- maximum(X,Y,Y1), maxlist(Xs,Y1,M).
     maxlist([],M,M).
 
	maximum(X,Y,Y) :- X =< Y.
	maximum(X,Y,X) :- X > Y.
 
%  Program 8.9    Finding the maximum of a list of integers

Comments

pl/prolog/pllib/max.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0