Files
30-seconds-of-code/snippets/gcd.md
Angelos Chalaris 08810dd64e Update some snippets
2019-08-20 10:45:53 +03:00

20 lines
288 B
Markdown

---
title: gcd
tags: math,beginner
---
Calculates the greatest common divisor of a list of numbers.
Use `reduce()` and `math.gcd` over the given list.
```py
from functools import reduce
import math
def gcd(numbers):
return reduce(math.gcd, numbers)
```
```py
gcd([8,36,28]) # 4
```