MathGroup Archive 2006

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

Search the Archive

RE: generalized foldlist problem


Arek,

You will probably get better answers but here is one approach.

list1 = {a, b, c, d, e};
list2 = {3, 2, 5, 1, 6};

f[i_] := Take[
    Join[Array[0 &, i - 1], Array[Part[list1, i] &, Part[list2, i]], 
      Array[0 &, 5]], 5]

Fold[#1 + f[#2] &, {0, 0, 0, 0, 0}, Range[5]]
{a, a + b, a + b + c, c + d, c + e}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/ 



From: Arkadiusz Majka [mailto:Arkadiusz.Majka at telekomunikacja.pl]
To: mathgroup at smc.vnet.net


DearAll,

Please, help!

I have two list

list1={a,b,c,d,e}
list2={3,2,5,1,6}

and I want to apply a modified version of FoldList to list1 in the
following way: list2 indicates that element a appears only 3 times (if
space enough) beginning from the beginning of the list , element b
appears 2 times, c - 5 times , etc.

So the output should be

GeneralizedFoldList[list1,list2]={a,a+b,a+b+c,c+d,c+e}

Thanks for any hints,

arek



  • Prev by Date: Re: random 3D object consisting of cuboids
  • Next by Date: Re: Something wrong with my FrontEnd?
  • Previous by thread: Re: generalized foldlist problem
  • Next by thread: Re: generalized foldlist problem