1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
% problem 2 solve:- fibo([2,1],Fibo), even_sum(Fibo,Sum), write(Sum). even_sum([],0):-!. even_sum([First|Rest],Sum):- First mod 2 =:= 0, !, even_sum(Rest,Sum1), Sum is First + Sum1. even_sum([_|Rest],Sum):- even_sum(Rest,Sum). fibo([First|Rest],Rest):- First >= 4000000, !. fibo([P1,P2|Rest],Out):- P0 is P1 + P2, fibo([P0,P1,P2|Rest],Out). |
実行結果:
1 ?- solve.
***********************(解答伏せます)**********************
true.