Prolog, find minimum in a list

前端 未结 13 1956
佛祖请我去吃肉
佛祖请我去吃肉 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 02:03

    min([Second_Last, Last], Result):-
        Second_Last < Last
     -> Result = Second_Last
     ;  Result = Last, !.
    
    min([First, Second|Rest], Result):-
        First < Second
     -> min([First|Rest], Result)
     ;  min([Second|Rest], Result).
    

    Should be working.

提交回复
热议问题