forked from hofmannol/AlgoDatSoSe25
fixed one-off error and improved call-logic
This commit is contained in:
parent
364590c563
commit
3926d8d0c7
@ -53,8 +53,9 @@ def _max_sequence_3_sub(z: MemoryArray, l: Literal, m: Literal, r: Literal):
|
|||||||
# find max-sum from Middle to right
|
# find max-sum from Middle to right
|
||||||
rechtsMax = MemoryCell(MIN_VALUE)
|
rechtsMax = MemoryCell(MIN_VALUE)
|
||||||
sum.set(0);
|
sum.set(0);
|
||||||
|
# MRange is exclusive
|
||||||
startRight = MemoryCell(1) + m
|
startRight = MemoryCell(1) + m
|
||||||
for i in mrange(startRight, r):
|
for i in mrange(startRight, MemoryCell(1) + r):
|
||||||
sum += z[i]
|
sum += z[i]
|
||||||
if sum > rechtsMax:
|
if sum > rechtsMax:
|
||||||
rechtsMax.set(sum)
|
rechtsMax.set(sum)
|
||||||
@ -63,6 +64,7 @@ def _max_sequence_3_sub(z: MemoryArray, l: Literal, m: Literal, r: Literal):
|
|||||||
|
|
||||||
def _max_sequence_3(z: MemoryArray, l: Literal, r: Literal):
|
def _max_sequence_3(z: MemoryArray, l: Literal, r: Literal):
|
||||||
# Calc-Vars -> illegal to use Literal(0) here? Probably
|
# Calc-Vars -> illegal to use Literal(0) here? Probably
|
||||||
|
# CAN ALLLL BE LITERALS
|
||||||
linksMax = MemoryCell()
|
linksMax = MemoryCell()
|
||||||
linksL = MemoryCell()
|
linksL = MemoryCell()
|
||||||
linksR = MemoryCell()
|
linksR = MemoryCell()
|
||||||
@ -79,7 +81,8 @@ def _max_sequence_3(z: MemoryArray, l: Literal, r: Literal):
|
|||||||
return (z[l], l, r)
|
return (z[l], l, r)
|
||||||
# calc middle
|
# calc middle
|
||||||
m.set(MemoryCell(l) + r)
|
m.set(MemoryCell(l) + r)
|
||||||
m /= Literal(2);
|
# Use cutoff/floor here, did not check
|
||||||
|
m //= Literal(2);
|
||||||
# get maxLeft, then maxRight and then cross them (rec)
|
# get maxLeft, then maxRight and then cross them (rec)
|
||||||
(linksMax, linksL, linksR) = _max_sequence_3(z, l, m)
|
(linksMax, linksL, linksR) = _max_sequence_3(z, l, m)
|
||||||
startRight = MemoryCell(1) + m
|
startRight = MemoryCell(1) + m
|
||||||
@ -152,9 +155,11 @@ def analyze_complexity(max_sequence_func, sizes):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
fn = max_sequence_4
|
# fn = max_sequence_4
|
||||||
|
for fn in [max_sequence_1, max_sequence_2, max_sequence_3, max_sequence_4]:
|
||||||
example(fn)
|
example(fn)
|
||||||
for filename in ["data/seq0.txt", "data/seq1.txt", "data/seq2.txt"]:
|
# for filename in ["data/seq0.txt", "data/seq1.txt", "data/seq2.txt", "data/seq3.txt"]:
|
||||||
|
for filename in ["data/seq0.txt", "data/seq1.txt"]:
|
||||||
print(filename)
|
print(filename)
|
||||||
seq(filename, fn)
|
seq(filename, fn)
|
||||||
analyze_complexity(fn, [10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
|
analyze_complexity(fn, [10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user