/ Published in: Prolog
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
sum(N, N, N). sum(Start, End, Total) :- Start < End, applicable(Start), Next is Start + 1, sum(Next, End, SemiTotal), Total is SemiTotal + Start, !. sum(Start, End, Total) :- Start < End, Next is Start + 1, sum(Next, End, Total). applicable(Number) :- divisible(Number, 3). applicable(Number) :- divisible(Number, 5). divisible(Number, 0) :- write('Error: division by 0'). divisible(Number, Divisor) :- Number mod Divisor =:= 0.
URL: http://13tazer31.wordpress.com/2011/02/06/problem-1/