MathGroup Archive 1998

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

Search the Archive

Re: Split in Mathematica 2.2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg12840] Re: Split in Mathematica 2.2
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Wed, 17 Jun 1998 00:27:47 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

For any one who interested in this topic: here is quite fast functional
program which simulates Split and works in Mathematica 2.2. It's based
on the same idea as Xah Lee procedural code: find the places where the
sequence should be split, insert markers and use Take. My earlier
version had a couple of bugs in it: it did not work when elements were
themselves lists (pointed out by Xah Lee) and got into trouble if the
list  contained a repeat element at the beginning. This one should work
always (I hope).

split[l_,fQ_:SameQ]:=
  Module[{m,H},
    Map[Take[l,#]&,
        Partition[
            Insert[Insert[
                Flatten[
                  Position[
                   
Partition[Map[#/.List->H&,l],2,1]/.{x_,y_}/;Not[fQ[x,y]]->
                       
m,m]],0,1],Length[l],-1],2,1]/.{a_,b_}->{a+1,b}]/.H->
        List]

Andrzej Kozlowski



  • Prev by Date: Re: Need help for a simple equation
  • Next by Date: Re: The Power Set
  • Previous by thread: Re: Split in Mathematica 2.2
  • Next by thread: Re: Re: Split in Mathematica 2.2