greatest-common-divisor

Can't find common elements is two lists

Can't find common elements is two lists Question: I’m writing a little python program, which is supposed to find the greatest common divisor between two numbers. Until now everything went fine but I can’t get the program to find the correct common elements in the two lists the program provides. Also you can see that …

Total answers: 1

Euclidean algorithm (GCD) with multiple numbers?

Euclidean algorithm (GCD) with multiple numbers? Question: So I’m writing a program in Python to get the GCD of any amount of numbers. def GCD(numbers): if numbers[-1] == 0: return numbers[0] # i’m stuck here, this is wrong for i in range(len(numbers)-1): print GCD([numbers[i+1], numbers[i] % numbers[i+1]]) print GCD(30, 40, 36) The function takes a …

Total answers: 10

What algorithm does Python employ in fractions.gcd()?

What algorithm does Python employ in fractions.gcd()? Question: I’m using the fractions module in Python v3.1 to compute the greatest common divisor. I would like to know what algorithm is used. I’m guessing the Euclidean method, but would like to be sure. The docs (http://docs.python.org/py3k/library/fractions.html?highlight=fractions.gcd#fractions.gcd) don’t help. Can anybody clue me in? Asked By: Justin …

Total answers: 3