MathGroup Archive 2005

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

Search the Archive

Re: A NewBie Question


This may seem tedious as well, of course:

Clear[f,g]
f[{x___,a_List,b:{n_,c___}}]:={x,Take[a,n],Drop[a,n],{c}}
f[x_]:=x
g[x_List,y:{__Integer?(#1<=0&)}]:=Drop[FixedPoint[f,{PadRight[x,
     Plus@@y,x],y},50],-2]
g[{a,b,c,d,e,f,g,h,i},{2,3,4}]
g[{a,b,c,d,e,f,g,h,i},{2,3,4,0,7}]

{{a,b},{c,d,e},{f,g,h,i}}

{{a,b},{c,d,e},{f,g,h,i},{},{a,b,c,d,e,f,g}}

Bobby

On Wed, 19 Jan 2005 01:59:34 -0500 (EST), Zhe Hu <iamhuzhe at gmail.com> wrote:

> Is there a way to take parts of a list as follows:
>
> takeParts[{a,b,c,d,e,f,g,h,i}, {2,3,4}]
>
> {{a,b}, {c,d,e}, {f,g,h,i}}
>
> A tedious way might be transforming {2, 3, 4} into {{1,2}, {3,5}, {6,
> 9}} (by Fold) and then Part/@ onto it. Is there a simpler way to do
> it?
>
> Thanks,
> Hu Zhe
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: A NewBie Question
  • Next by Date: Re: compile / optimize
  • Previous by thread: Re: A NewBie Question
  • Next by thread: Re: A NewBie Question