Last active
October 1, 2016 16:24
-
-
Save giampaolo44/2369faa4892b184013aa9202819f1cf5 to your computer and use it in GitHub Desktop.
minimo comune denominatore
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Sat Oct 1 16:08:20 2016 | |
@author: giampaolo | |
""" | |
def gcdRecur(a, b): | |
''' | |
a, b: positive integers | |
returns: a positive integer, the greatest common divisor of a & b. | |
''' | |
print("primo",a,b) | |
if a<b: | |
remainder=b | |
b=a | |
a=remainder | |
#remainder=a | |
if b==0 or a==b: | |
return a | |
else: | |
remainder=a | |
print("secondo",a,b,remainder-b) | |
while remainder-b>=b: | |
# remainder2=remainder | |
remainder-=b | |
print("terzo",a,b,remainder-b) | |
if remainder-b==0: | |
print("quarto",a,b,remainder-b) | |
return(b) | |
else: | |
print("quinto",a,b,remainder-b) | |
return gcdRecur(b,remainder-b) | |
print(gcdRecur(9,12)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Standard version:
Short version:
Generic version: