Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. def get_next_block(idx, A):
  2. chopped = A[idx+1:idx+7]
  3. agg = 0
  4. last_idx = -1
  5. for i, v in enumerate(chopped):
  6. if v > -1:
  7. agg += v
  8. last_idx = i
  9.  
  10. if last_idx == -1:
  11. max_val = -10001
  12. for i, v in enumerate(chopped):
  13. if v > max_val:
  14. max_val = v
  15. last_idx = i
  16.  
  17. agg = max_val
  18.  
  19. return agg, last_idx + 1 + idx
  20.  
  21. def solution(A):
  22. # the solution is starting with the first number take all positive numbers in the
  23. # next block of 6. If there is no positive number in the next block of 6, then take
  24. # the largest (least negative or zero) number in that next block.
  25. # Then move to the next block of six after the last number taken.
  26.  
  27. idx = 0
  28. total = A[0]
  29. while True:
  30. agg, idx = get_next_block(idx, A)
  31. print('adding %d' % agg)
  32. total += agg
  33. if idx == -1:
  34. break
  35.  
  36. if idx == len(A) - 1:
  37. break
  38.  
  39. return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement