Posted By

13tazer31 on 02/07/11


Tagged

math prolog project-euler


Versions (?)

Project Euler - Problem 1


 / Published in: Prolog
 

URL: http://13tazer31.wordpress.com/2011/02/06/problem-1/

  1. sum(N, N, N).
  2. sum(Start, End, Total) :-
  3. Start < End,
  4. applicable(Start),
  5. Next is Start + 1,
  6. sum(Next, End, SemiTotal),
  7. Total is SemiTotal + Start, !.
  8. sum(Start, End, Total) :-
  9. Start < End,
  10. Next is Start + 1,
  11. sum(Next, End, Total).
  12.  
  13.  
  14. applicable(Number) :-
  15. divisible(Number, 3).
  16. applicable(Number) :-
  17. divisible(Number, 5).
  18.  
  19.  
  20. divisible(Number, 0) :-
  21. write('Error: division by 0').
  22. divisible(Number, Divisor) :-
  23. Number mod Divisor =:= 0.

Report this snippet  

You need to login to post a comment.