CLPFDライブラリ読み込んでるけど使ってなかった…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
:-use_module(library(clpfd)). adding(1,0):-!. adding(Idx,Sum):- (Idx mod 3 =:= 0 ; Idx mod 5 =:= 0), !, Idx1 is Idx - 1, adding(Idx1,Sum1), Sum is Sum1 + Idx. adding(Idx,Sum):- !, Idx1 is Idx - 1, adding(Idx1,Sum). |
実行結果
[1] 2 ?- adding(999,R).
***********************(解答伏せます)**********************