Posted By

13tazer31 on 02/07/11


Tagged

math prolog project-euler


Versions (?)

Project Euler - Problem 2


 / Published in: Prolog
 

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

  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.

Report this snippet  

You need to login to post a comment.