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.

linear.py 877B

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