1 Replies - 1305 Views - Last Post: 01 December 2010 - 09:50 PM

#1 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

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

GCD in prolog

Posted 25 March 2009 - 07:17 PM

Description: a simple snippet in prolog to find the greatest common divisor of 2 numbers
gcd(X, X, X).

gcd(X, Y, Z):-
	X > Y, X1 is X - Y, gcd(X1, Y, Z).

gcd(X, Y, Z):-
	Y > X, Y1 is Y - X, gcd(X, Y1, Z).


Is This A Good Question/Topic? 0
  • +

Replies To: GCD in prolog

#2 zishan89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 01-December 10

Re: GCD in prolog

Posted 01 December 2010 - 09:50 PM

gcd(A,0,A). gcd(A,B,C):-(A>B),(B>0),R is A mod B,gcd(B,R,C). gcd(A,B,C):-(A
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1