challenges/e1/e1.pl

8 lines
377 B
Prolog

divisible_3_5(N) :- 0 is N rem 3 ; 0 is N rem 5.
sum_divisors(End, End, Total, Total).
sum_divisors(Start, End, Acc, Total) :- divisible_3_5(Start), Next is Start + 1, NewAcc is Acc + Start, sum_divisors(Next, End, NewAcc, Total).
sum_divisors(Start, End, Acc, Total) :- Next is Start + 1, sum_divisors(Next, End, Acc, Total).
e1(Result) :- sum_divisors(2, 1000, 0, Result).