curriculum/challenges/english/blocks/daily-coding-challenges-python/68f6587287ad1f4ad39b0c83.md
Given two positive integers, return their greatest common divisor (GCD).
For example, the divisors of 4 are 1, 2, and 4. The divisors of 6 are 1, 2, 3, and 6. So given 4 and 6, return 2, the largest number that appears in both sets of divisors.
gcd(4, 6) should return 2.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(gcd(4, 6), 2)`)
}})
gcd(20, 15) should return 5.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(gcd(20, 15), 5)`)
}})
gcd(13, 17) should return 1.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(gcd(13, 17), 1)`)
}})
gcd(654, 456) should return 6.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(gcd(654, 456), 6)`)
}})
gcd(3456, 4320) should return 864.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(gcd(3456, 4320), 864)`)
}})
def gcd(x, y):
return x
def gcd(x, y):
while y != 0:
x, y = y, x % y
return x