List max element

Description

Finding greates element from list

Source: PROLOG str. 197 Wydawnictwo PLJ Warszawa 1991 ISBN 83-85190-63-5

Download

Program source code: list_max_element.pl

Listing

max([H|[]], H).
max([H|T], Maximum) :- max(T, M1), mx(H, M1, Maximum), !.
mx(X, Y, X) :- X > Y.
mx(X, Y, Y) :- X =< Y.
 
test :- max([6, 2, 5, 4, 8], M).

Comments

pl/prolog/pllib/list_max_element.txt · ostatnio zmienione: 2017/07/17 08:08 (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