Prolog, find minimum in a list

前端 未结 13 1926
佛祖请我去吃肉
佛祖请我去吃肉 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.

    0 讨论(0)
提交回复
热议问题