SHARE
TWEET

Untitled

a guest Dec 13th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. divisibleForPrime(X,Y) :-
  2.     0 is mod(X, Y), !.
  3.  
  4. divisibleForPrime(X,Y) :-
  5.     X > Y+1,
  6.     divisible(X, Y+1).
  7.    
  8. divisible(X,Y) :-
  9.     0 is mod(X, Y).
  10.  
  11. isPrime(2) :-
  12.     true.
  13. isPrime(X) :-
  14.     X < 2.
  15. isPrime(X) :-
  16.     not(divisibleForPrime(X, 2)).
  17.  
  18. writePrimes(X,Y,[]):-
  19.     X is Y, !.
  20.  
  21. writePrimes(X, Y, [N|WYNIK]) :-
  22.     N is Y + 1,
  23.     isPrime(N),
  24.     divisible(X, N),
  25.     X1 is X//N,
  26.     writePrimes(X1, WYNIK).
  27.  
  28. writePrimes(X, Y, WYNIK) :-
  29.     N is Y + 1,
  30.     isPrime(N),
  31.     not(divisible(X, N)),
  32.     writePrimes(X, N, WYNIK).
  33.  
  34. writePrimes(X, Y, WYNIK) :-  
  35.     N is Y + 1,
  36.     not(isPrime(N)),
  37.     writePrimes(X, N, WYNIK).
  38.    
  39. writePrimes(X, O) :-
  40.     Y is 1,
  41.     writePrimes(X, Y, O).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top