Welcome, guest | Sign In | My Account | Store | Cart

I wrote this little piece of code as part of my ongoing python-math projects. For more information please checkout The Living Pearl.

Python, 17 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def gcd(a,b):
	t = b
	b = a % b
	
	if b == 0:
		return t
	else:
		return gcd(t,b)
		
def main(argv):
	if (len(sys.argv) != 3):
		sys.exit('Usage: gcd.py <a> <b>')
	
	print abs(gcd(int(sys.argv[1]),int(sys.argv[2])))

if __name__ == "__main__":
	main(sys.argv[1:])
Created by Captain DeadBones on Wed, 16 Jan 2013 (MIT)
Python recipes (4591)
Captain DeadBones's recipes (47)

Required Modules

  • (none specified)

Other Information and Tasks