0 Replies - 257 Views - Last Post: 29 March 2009 - 07:45 PM

#1 mostyfriedman   User is offline

  • The Algorithmi
  • member icon

Reputation: 729
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

checks if a number is prime or not in PROLOG

Posted 29 March 2009 - 07:45 PM

Description: a snippet in PROLOG that checks if a number is prime or not
divisible(X, Y):-
	N is Y*Y, N =< X, X mod Y =:= 0.

divisible(X, Y):-
	 Y < X, Y1 is Y + 1, divisible(X, Y1).

isprime(X):-
	Y is 2, X > 1 , +divisible(X, Y).


Is This A Good Question/Topic? 0
  • +

Page 1 of 1