This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
DSA/GA1/ga1_last.py

30 lines
545 B
Python
Executable File

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()