Differences

This shows you the differences between two versions of the page.

notes:peere:time [2019/05/01 16:38]
notes:peere:time [2019/05/01 22:44] (current)
Line 170: Line 170:
<code> <code>
def changeTime(a,p): def changeTime(a,p):
-   i = 0; t = p[i]; v = 0; b = []+   i = 0; t = p[i]; v = 0; b = []; cut = False
for sc,fc,vc in a:    for sc,fc,vc in a:
-      while t <= sc: i = i+1; t = p[i] +      while t <= sc:
-      if t <fc: v = v + (t-sc)*vc; b.append((i,i+1,v))v = (fc-t)*vc +         if v > 0:
-      else: v = v + (fc-sc)*vc +            if not cut: b.append((i,i+1,v)); v = 0
-   b.append((i,i+1,v))+         i = i+1; t = p[i]
+      if t < fc:
+         v = v + (t-sc)*vc; b.append((i,i+1,v))
+         v = (fc-t)*vc; cut = True
+      else: v = v + (fc-sc)*vc; cut = False
+   if v > 0: b.append((i,i+1,v))
return(b)    return(b)

>>> A = [(2,6,1),(8,9,3),(10,13,2),(13,15,4),(18,19,1)] >>> A = [(2,6,1),(8,9,3),(10,13,2),(13,15,4),(18,19,1)]
>>> P = [0,4,11,15,17,20] >>> P = [0,4,11,15,17,20]
->>> A
-[(2, 6, 1), (8, 9, 3), (10, 13, 2), (13, 15, 4), (18, 19, 1)]
->>> P
-[0, 4, 11, 15, 17, 20]
>>> changeTime(A,P) >>> changeTime(A,P)
[(1, 2, 2), (2, 3, 7), (3, 4, 12), (5, 6, 1)] [(1, 2, 2), (2, 3, 7), (3, 4, 12), (5, 6, 1)]