diff --git a/schoeffelbe/pr01.py b/schoeffelbe/pr01.py index a639e3b..b590dbb 100644 --- a/schoeffelbe/pr01.py +++ b/schoeffelbe/pr01.py @@ -39,7 +39,7 @@ def max_sequence_2(z: MemoryArray): return m, l, r def _max_sequence_3_sub(z: MemoryArray, l: Literal, m: Literal, r: Literal): - # find max-sum from Middle to left (including on elem from right) + # find max-sum from Middle to left linksMax = MemoryCell(MIN_VALUE) sum = MemoryCell(0) links = MemoryCell(l) @@ -50,7 +50,7 @@ def _max_sequence_3_sub(z: MemoryArray, l: Literal, m: Literal, r: Literal): linksMax.set(sum) links.set(i) - # find max-sum from Middle to right (inluding one elem from left) + # find max-sum from Middle to right rechtsMax = MemoryCell(MIN_VALUE) sum.set(0); startRight = MemoryCell(1) + m @@ -114,6 +114,7 @@ def max_sequence_4(z: MemoryArray): max.set(aktSum) links.set(aktLinks) rechts.set(i) + # if negative we start new Sum -> Restart must be better than continue if aktSum < Literal(0): aktSum.set(0) aktLinks.set(MemoryCell(1) + i)