Prolog, find minimum in a list

前端 未结 13 1935
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 01:25

in short: How to find min value in a list? (thanks for the advise kaarel)

long story:

I have created a weighted graph in amzi prolog and given 2 nodes, I am

13条回答
  •  借酒劲吻你
    2020-12-07 01:46

    This works and seems reasonably efficient.

    min_in_list([M],M).    
    min_in_list([H|T],X) :-
        min_in_list(T,M),
        (H < M, X = H; X = M).   
    
    min_list(X,Y) :- min_in_list(X,Y), !.
    

提交回复
热议问题