mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
utils/misc: add gcd_multiple function to compute GCD or any number of integers
This commit is contained in:
parent
c13fe1bc63
commit
adffec35f6
1 changed files with 9 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
from fractions import gcd
|
||||
import collections
|
||||
|
||||
def flat_iteration(l):
|
||||
|
@ -26,3 +27,11 @@ def autotype(s):
|
|||
except ValueError:
|
||||
pass
|
||||
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 a new issue