dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 68f6587287ad1f4ad39b0c83 | Challenge 97: GCD | 29 | challenge-97 |
--description--
Given two positive integers, return their greatest common divisor (GCD).
- The GCD of two integers is the largest number that divides evenly into both numbers without leaving a remainder.
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.
--hints--
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)`)
}})
--seed--
--seed-contents--
def gcd(x, y):
return x
--solutions--
def gcd(x, y):
while y != 0:
x, y = y, x % y
return x