Mapytex/arithmetic.py

32 lines
575 B
Python
Raw Normal View History

#!/usr/bin/env python
# encoding: utf-8
def gcd(a, b):
2013-08-07 23:12:11 +00:00
"""Compute gcd(a,b)
2013-08-07 23:12:11 +00:00
:param a: first number
:param b: second number
:returns: the gcd
2013-08-07 23:12:11 +00:00
"""
if a > b:
c = a % b
else:
c = b % a
2013-08-07 23:12:11 +00:00
if c == 0:
return min(a,b)
elif a == 1:
return b
elif b == 1:
return a
else:
return gcd(min(a,b), c)
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del