fork(1) download
  1. import numpy
  2. import time
  3.  
  4. arr = [5, 3, 1, 3, 5, 2, 5, 3, 1, 3, 5, 2, 5]
  5. arr1 = [1, 1, 1, 1]
  6. arr2 = [3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1, 3]
  7. arr3 = [5, 4, 2, 1, 5]
  8. arr4 = [4, 3, 4, 3, 4, 2, 4, 3, 4, 3, 4, 2, 4]
  9. arr5 = [4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4]
  10. arr_time = list((numpy.random.rand(29999) * 10).astype(int))
  11. arr_time.append(arr_time[0])
  12.  
  13. def sectors(arr):
  14. l, last = 0, len(arr) - 1
  15. while l < last:
  16. l = arr[l+1:].index(arr[0]) + l + 1
  17. if last % l != 0:
  18. continue
  19. for i in range(last // l):
  20. if arr[0:l] != arr[l * i: l * (i + 1)]:
  21. break
  22. else:
  23. break
  24. return l
  25.  
  26. a = sectors(arr)
  27. b = sectors(arr1)
  28. c = sectors(arr2)
  29. d = sectors(arr3)
  30. e = sectors(arr4)
  31. f = sectors(arr5)
  32.  
  33. print(a,b,c,d,e,f)
  34.  
  35. t = time.time()
  36. print(sectors(arr_time))
  37. print("Array of %d elements took %.3f seconds to process" % (len(arr_time), time.time() - t))
Success #stdin #stdout 0.18s 27280KB
stdin
Standard input is empty
stdout
6 1 3 4 6 2
29999
Array of 30000 elements took 0.094 seconds to process