/ Published in: Prolog
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
fibonacci(_,Current,End,0) :- Current > End. fibonacci(Previous, Current, End, Total) :- divisible(Current, 2), Next is Current + Previous, fibonacci(Current, Next, End, Sum), Total is Sum + Current, !. fibonacci(Previous, Current, End, Total) :- Next is Current + Previous, fibonacci(Current, Next, End, Total). divisible(Number, 0) :- write('Error: division by 0'). divisible(Number, Divisor) :- Number mod Divisor =:= 0.
URL: http://13tazer31.wordpress.com/2011/02/06/project-euler-problem-2/