Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

25
snippets/python/s/lcm.md Normal file
View File

@ -0,0 +1,25 @@
---
title: Least common multiple
type: snippet
language: python
tags: [math,list]
cover: fruit-feast
dateModified: 2020-11-02T19:31:15+02:00
---
Returns the least common multiple of a list of numbers.
- Use `functools.reduce()`, `math.gcd()` and `lcm(x, y) = x * y / gcd(x, y)` over the given list.
```py
from functools import reduce
from math import gcd
def lcm(numbers):
return reduce((lambda x, y: int(x * y / gcd(x, y))), numbers)
```
```py
lcm([12, 7]) # 84
lcm([1, 3, 4, 5]) # 60
```