Re: how to sum lists of unequal length?
- To: mathgroup at smc.vnet.net
- Subject: [mg70402] Re: how to sum lists of unequal length?
- From: "dkr" <dkrjeg at adelphia.net>
- Date: Sun, 15 Oct 2006 00:20:01 -0400 (EDT)
- References: <egq2th$84h$1@smc.vnet.net>
Arek, A padded approach: addLists1[s:{__List}]:= Module[{len=Max[Length/@s]},Plus[Sequence@@(PadRight[#,len]&/@s)]]; A non-padded approach: g[x_List,y_List]:=Module[{lenx=Length[x],leny=Length[y]}, Switch[Sign[lenx-leny],0,x+y,1,Join[Take[x,leny]+y,Drop[x,leny]],_, Join[Take[y,lenx]+x,Drop[y,lenx]] ]]; addLists2[s:{__List}]:=Fold[g[##]&,{0},s]; dkr