将结果标记为列表?

labeling results into List?

我想写一个谓词,可以 sum_all 使用预测 lucky/5

的幸运数字
:- use_module(library(clpfd)).

lucky(A,B,C,D,N) :-
L = [A,B,C,D],
L ins 0..9,
N #= A*1000+B*100+C*10+D,
A+B #= C+D,
labeling([],L).

sum_all():-
% I want to write a code that computes the sum of all lucky numbers

如果你的 Prolog 有库(aggregate),你可以

?- aggregate_all((count,sum(N)), lucky(_,_,_,_,N), (Count,Sum)).
Count = 670,
Sum = 3349665.