Update some snippets
This commit is contained in:
@ -1,17 +1,18 @@
|
||||
---
|
||||
title: gcd
|
||||
tags: math
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Calculates the greatest common divisor of a list of numbers.
|
||||
|
||||
Uses the reduce function from the inbuilt module `functools`. Also uses the `math.gcd` function over a list.
|
||||
Use `reduce()` and `math.gcd` over the given list.
|
||||
|
||||
```py
|
||||
from functools import reduce
|
||||
import math
|
||||
|
||||
def gcd(numbers):
|
||||
return reduce(math.gcd, numbers)
|
||||
return reduce(math.gcd, numbers)
|
||||
```
|
||||
|
||||
```py
|
||||
|
||||
Reference in New Issue
Block a user