Update some snippets

This commit is contained in:
Angelos Chalaris
2019-08-20 10:45:53 +03:00
parent 8a0fd59a72
commit 08810dd64e
7 changed files with 31 additions and 101 deletions

View File

@ -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