gpt4 book ai didi

prolog - 将结果标记为列表?

转载 作者:行者123 更新时间:2023-12-01 15:03:51 25 4
gpt4 key购买 nike

我想写一个谓词,可以使用预测 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.

关于prolog - 将结果标记为列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52580682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com