Created
July 24, 2017 20:25
-
-
Save kanglicheng/065ef3f7e1729b591b45c946e5c9fbc2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def convertFracts(lst): | |
n= len(lst) | |
ans =[[0]*2 for _ in range(n)] | |
for i in range(n): | |
ans[i][0]=lst[i][0]/gcd(lst[i][0], lst[i][1]) | |
ans[i][1] = lst[i][1]/gcd(lst[i][0], lst[i][1]) | |
return ans | |
def gcd(a, b): | |
"""Return greatest common divisor using Euclid's Algorithm.""" | |
while b: | |
a, b = b, a % b | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment