MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Adding the elements of a list sequentially

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109357] Re: Adding the elements of a list sequentially
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 23 Apr 2010 03:48:40 -0400 (EDT)
  • References: <hqotti$9ch$1@smc.vnet.net>

On Apr 22, 12:29 am, eba... 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

a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
b = {1, 2};

Total@PadRight@{a, b}
{2, 4, 3, 4, 5, 6, 7, 8, 9, 10}

Total@PadRight@{b, a}
{2, 4, 3, 4, 5, 6, 7, 8, 9, 10}


  • Prev by Date: Re: Unevaluated functions
  • Next by Date: Re: Adding the elements of a list sequentially
  • Previous by thread: Re: Adding the elements of a list sequentially
  • Next by thread: Re: Adding the elements of a list sequentially