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.

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