utils/misc: add gcd_multiple function to compute GCD or any number of integers
This commit is contained in:
parent
c13fe1bc63
commit
adffec35f6
|
@ -1,3 +1,4 @@
|
||||||
|
from fractions import gcd
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
def flat_iteration(l):
|
def flat_iteration(l):
|
||||||
|
@ -26,3 +27,11 @@ def autotype(s):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
def gcd_multiple(numbers):
|
||||||
|
l = len(numbers)
|
||||||
|
if l == 1:
|
||||||
|
return numbers[0]
|
||||||
|
else:
|
||||||
|
s = l//2
|
||||||
|
return gcd(gcd_multiple(numbers[:s]), gcd_multiple(numbers[s:]))
|
||||||
|
|
Loading…
Reference in New Issue