Skip to content

Instantly share code, notes, and snippets.

@grantwforsythe
Last active February 22, 2023 15:13
Show Gist options
  • Save grantwforsythe/0bfab8f0738609731d01b5deaa111bff to your computer and use it in GitHub Desktop.
Save grantwforsythe/0bfab8f0738609731d01b5deaa111bff to your computer and use it in GitHub Desktop.
Find the greatest common divisor between two integers
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)
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