Added test file for Graded Assignment 1

This commit is contained in:
Claudio Maggioni (maggicl) 2019-03-24 16:15:30 +01:00
parent 85f6fe46dc
commit 414b0304be

29
ga1_last.py Normal file
View file

@ -0,0 +1,29 @@
import random
def calc(A):
n = len(A)
res = 0
for i in range(0,n):
for j in range(i+1, n):
res += A[j] - A[i]
return res
def calc2(A):
n = len(A)
res = 0
for i in range(0,n):
res += (2*(i+1)-n-1)*A[i]
return res
def main():
for i in range(0,100):
A = []
for j in range(0,i):
A.append(random.randint(0,1000000))
if not calc(A) == calc2(A):
print("wrong!")
return
print("ok!")
if __name__ == "__main__":
main()