List smallest element

Description

Finding least lemenet from list

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

Download

Program source code: list_smallest_element.pl

Listing

min([H|[]], H).
min([H|T], Minimum) :- min(T, M1), mn(H, M1, Minimum), !.
mn(X, Y, X) :- X < Y.
mn(X, Y, Y) :- X >= Y.
 
test :- min([4, 6, 3, 2, 8], M).

Comments

pl/prolog/pllib/list_smallest_element.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