Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg69129] Re: generalized foldlist problem
  • From: "dkr" <dkrjeg at adelphia.net>
  • Date: Wed, 30 Aug 2006 06:35:11 -0400 (EDT)
  • References: <ed0rja$sll$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Arek,

No need to use Fold or FoldList.

In[1]:=
fn[list1_List,list2_List]:=
With[{len=Length[list1]+1},Plus@@(Join[Table[0,{#1-1}],Table[list1[[#1]],{Min[#2,len-#1]}],Table[0,{len-#1-#2}]]&@@@Thread[{Range[len-1],list2}])];
In[2]:=
fn[{a,b,c,d,e},{3,2,5,1,6}]
Out[2]=
{a,a+b,a+b+c,c+d,c+e}

dkr


  • Prev by Date: Re: using FindRoot to find multiple answers in a domain?
  • Next by Date: transforming a rule of lists to a list of rules
  • Previous by thread: Re: generalized foldlist problem
  • Next by thread: RE: generalized foldlist problem