Challenge 1: Find the Greatest Common Divisor

Given two numbers, find their greatest common divisor.

Problem Statement

Implement a function that takes two numbers, testVariable1 and testVariable2 and returns their greatest common divisor.

What is the Greatest Common Divisor?

Greatest Common Divisor of two or more integers is the largest positive integer that divides each of the integers.

For example, take two numbers 4242 and 5656.

4242 can be completely divided by 11, 22, 33, 66, 77, 1414, 2121 and 4242.

5656 can be completely divided by 11, 22, 44, 77, 88, 1414, 2828 and 5656.

Therefore the greatest common divisor of 4242 and 5656 is 1414.

Input

Two variables testVariable1 and testVariable2 containing numbers.

Output

The greatest common divisor of testVariable1 and testVariable2.

Sample Input

6, 9

Sample Output

3

Try it Yourself

Try to attempt this challenge by yourself before moving on to the solution. Good luck!

Press + to interact
def gcd(testVariable1, testVariable2) :
# Write your code here
return None

Let’s have a look at the solution review of this problem.