Re: Adding the elements of a list sequentially

*To*: mathgroup at smc.vnet.net*Subject*: [mg109349] Re: Adding the elements of a list sequentially*From*: Bob Hanlon <hanlonr at cox.net>*Date*: Fri, 23 Apr 2010 03:47:12 -0400 (EDT)

Your first example does not seem to be consistent with what you described. f[a_?VectorQ, b_?VectorQ] := a + PadRight[b, Length[a], b]; a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; b = {1, 2}; f[a, b] {2,4,4,6,6,8,8,10,10,12} f[b, a] {2,4} a = {1, 1, 1, 1, 1}; b = {1, 2, 3}; f[a, b] {2,3,4,2,3} f[b, a] {2,3,4} Bob Hanlon ---- ebaugh at illinois.edu wrote: ============= I am looking for an efficient way to add the elements of a list sequentially onto another list For example, generate list c, given lists a and b: a = {1,2,3,4,5,6,7,8,9,10} b = {1,2} c = {2,4,4,5,6,7,8,9,10,11} another example: a = {1,1,1,1,1} b = {1,2,3} c = {2,3,4,2,3} It seems like there must be a built in function to do this, but have been unable to find it. Thanks a 10^6 Jason Ebaugh