You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cubic.py 854B

6 months ago
6 months ago
1234567891011121314151617181920212223242526
  1. from SoSe24.algodat.foundation import AlgoDatArray, AlgoDatValue, read_int_sequence, MinusInf
  2. from time import perf_counter as pfc
  3. def maxfolge1(z: AlgoDatArray) -> (int, int, int):
  4. maximum = AlgoDatValue(MinusInf())
  5. current_sum = AlgoDatValue(0)
  6. left = AlgoDatValue(0)
  7. right = AlgoDatValue(0)
  8. for i in range(z.size):
  9. for j in range(i, z.size):
  10. current_sum.value = 0
  11. for k in range(i, j + 1):
  12. current_sum += z[k]
  13. if current_sum > maximum:
  14. maximum.value = current_sum.value
  15. left.value = i
  16. right.value = j
  17. return maximum.value, left, right
  18. if __name__ == "__main__":
  19. z = read_int_sequence("../../seq0.txt")
  20. start = pfc()
  21. print(maxfolge1(z))
  22. print(f"Dauer: {pfc() - start:.4f}s")
  23. AlgoDatValue.summary()