ALGORITHMS AND COMPLEXITY

farhankhan
week1GCD1.py-runwithpython3

#Compacted routine for GCD. Show taht this is the same as slide 1 of the exercise slides above def hcf(a, b): ''' Calculate the Highest Common Factor of both numbers ''' print(f'Highest Common Factor of {a} and {b}...') x = a y = b counter = 0 while x != y: counter += 1 if x > y: x = x - y print(f'\tAdjust X to: {x:6}') elif x < y: y = y - x print(f'\tAdjust Y to: {y:6}') print(f'Highest Common Factor is: {x:6}') print(f'Iterations used: {counter}\n\n') hcf(97, 83) hcf(10, 25) hcf(14, 147) hcf(34565, 2000)