# Below are my solutions. # After that is code that I used to grade your assignment. # If you had an import statement or the code would not run due to error, you get a 0. # Otherwise, I ran 4 test cases per problem. # You got 3 points per successful case. # I set up the problem so that the input is a *single list*. # If you assumed the input is a pair, you got -1; use testb2() in that case. def egcd(li): a, b = li[0], li[1] s0, t0, s1, t1 = 1, 0, 0, 1 while b != 0: q = a//b a, b = b, a%b s0, t0, s1, t1 = s1, t1, s0-q*s1, t0-q*t1 return a, s0, t0 def testb(): test = [[35,14], [60656, 70245], [0, 829183], [7154855686, 108916455]] answer = [7, 223, 829183, 382163] c = 0 for i in range(4): (d, s, t) = egcd(test[i]) if d == answer[i] and s*test[i][0] + t*test[i][1] == d: c += 3 return c def testb2(): test = [[35,14], [60656, 70245], [0, 829183], [7154855686, 108916455]] answer = [7, 223, 829183, 382163] c = 0 for i in range(4): [d, s, t] = egcd(test[i][0],test[i][1]) if d == answer[i] and s*test[i][0] + t*test[i][1] == d: c += 3 return min(c,11)