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

288 B

title, tags
title tags
gcd math,beginner

Calculates the greatest common divisor of a list of numbers.

Use reduce() and math.gcd over the given list.

from functools import reduce
import math

def gcd(numbers):
  return reduce(math.gcd, numbers)
gcd([8,36,28]) # 4