Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

RE: generalized foldlist problem

  • To: mathgroup at
  • Subject: [mg69113] RE: [mg69057] generalized foldlist problem
  • From: "David Park" <djmp at>
  • Date: Wed, 30 Aug 2006 06:33:59 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


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 

From: Arkadiusz Majka [mailto:Arkadiusz.Majka at]
To: mathgroup at


Please, help!

I have two list


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


Thanks for any hints,


  • 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