fix identation
This commit is contained in:
@ -7,19 +7,19 @@ The `helperGcdfunction` uses recursion. Base case is when `y` equals `0`. In thi
|
|||||||
Uses the reduce function from the inbuild module `functools`. Also defines a method `spread` for javascript like spreading of arrays.
|
Uses the reduce function from the inbuild module `functools`. Also defines a method `spread` for javascript like spreading of arrays.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
def spread(arg):
|
def spread(arg):
|
||||||
ret = []
|
ret = []
|
||||||
for i in arg:
|
for i in arg:
|
||||||
if isinstance(i,list):
|
if isinstance(i,list):
|
||||||
ret.extend(i)
|
ret.extend(i)
|
||||||
else:
|
else:
|
||||||
ret.append(i)
|
ret.append(i)
|
||||||
return ret
|
return ret
|
||||||
def gcd(*args):
|
def gcd(*args):
|
||||||
numbers = []
|
numbers = []
|
||||||
numbers.extend(spread(list(args)))
|
numbers.extend(spread(list(args)))
|
||||||
def helperGcd(x,y):
|
def helperGcd(x,y):
|
||||||
return x if not y else gcd(y,x%y)
|
return x if not y else gcd(y,x%y)
|
||||||
return reduce((lambda x,y : helperGcd(x,y)),numbers)
|
return reduce((lambda x,y : helperGcd(x,y)),numbers)
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user