Project Euler - Problem 2


/ Published in: Prolog
Save to your folder(s)



Copy this code and paste it in your HTML
  1. fibonacci(_,Current,End,0) :-
  2. Current > End.
  3. fibonacci(Previous, Current, End, Total) :-
  4. divisible(Current, 2),
  5. Next is Current + Previous,
  6. fibonacci(Current, Next, End, Sum),
  7. Total is Sum + Current, !.
  8. fibonacci(Previous, Current, End, Total) :-
  9. Next is Current + Previous,
  10. fibonacci(Current, Next, End, Total).
  11.  
  12. divisible(Number, 0) :-
  13. write('Error: division by 0').
  14. divisible(Number, Divisor) :-
  15. Number mod Divisor =:= 0.

URL: http://13tazer31.wordpress.com/2011/02/06/project-euler-problem-2/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.