Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 28
#implement Euclidean Algorithm and count number of steps def EALength(a,b): #count number of steps in Euclidean Algorithm #if a<b then switch em if a < b: temp = a a = b b = temp r=b steps =0 while r>0: temp = b r = a% b a = temp b = r steps += 1 return steps def MaxSteps(N): Max = 0 maxx =0 maxy =0 for x in[1..N]: for y in [1..N]: EA = EALength(x,y) if(EA > Max): maxx =x maxy =y Max =EA print("x = ", maxx) print("y = ", maxy) print("Max steps: ", Max) def AverageSteps(N): total = 0 count = 0 for x in[1..N]: for y in [1..N]: EA = EALength(x,y) total += EA count += 1 AverageSteps = float(total/count) print("AverageSteps is ", AverageSteps) MaxSteps(50); AverageSteps(12);
('x = ', 21) ('y = ', 34) ('Max steps: ', 7) ('AverageSteps is ', 1.8888888888888888)
euler_phi(16)
8
p = matrix_plot(matrix(2,[1,1,3,3])) p