有些谓词值得学习:maplist/3
,select/3
,forall/2
:
gap(List, A, Output) :-
maplist([X,Y] >> (Y is abs(X-A)), List, Diffs), % make a list of abs diffs
select(Output, Diffs, Others), % select a diff
forall(member(Other, Others), Output >= Other). % check that is maximum
?- gap([1,10,50,100,120], 50, X).
X = 70