How make a list of cumulative sum in netlogo

前端 未结 4 981
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 06:43

How can i make a list of cumulative sum of a other list?

i tried it that way:

;;all temperatrue-values around the turtle saved in list 
set tempera         


        
4条回答
  •  心在旅途
    2021-01-07 07:11

    As Jen suggested, you can use foreach. Another nice approach is reduce:

    to-report partial-sums [#lst]
      set #lst (fput [0] #lst)  ;;prepare for reduce
      report butfirst reduce [lput (?2 + last ?1) ?1] #lst
    end
    

提交回复
热议问题