Last active
February 22, 2023 15:13
-
-
Save grantwforsythe/0bfab8f0738609731d01b5deaa111bff to your computer and use it in GitHub Desktop.
Find the greatest common divisor between two integers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gcd(x: int, y: int ) -> int: | |
""" Find the greatest common divisor between two integers """ | |
return x if y == 0 else gcd(y, x%y) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from gcd import gcd | |
class TestGCD(unittest.TestCase): | |
def test_gcd(self): | |
self.assertEqual(gcd(3094, 2513), 7) | |
self.assertEqual(gcd(1053, 481), 13) | |
if __name__ == '__main__': | |
unittest.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment