MathGroup Archive 1997

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

Search the Archive

Re: Partition List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8423] Re: Partition List
  • From: "Seth J. Chandler" <SChandler at uh.edu>
  • Date: Sat, 30 Aug 1997 00:42:31 -0400
  • Organization: University of Houston Law Center
  • Sender: owner-wri-mathgroup at wolfram.com

How about this

Test data

In[68]:=
test={14,19,19,17,15,11,10,9,19,8,18,11,9,5,10,15,2,12,15,12,18,1,2,9,2,13,12,


20,6,4,2,4,1,5,12,13,4,12,11,16,1,1,6,13,12,10,7,5,18,2,10,10,13,20,10,3,


8,12,16,2,12,12,6,17,17,20,0,7,1,11,3,0,13,0,16,14,20,4,12,15,3,18,18,1,

    12,12,0,13,20,5,15,8,17,10,9,14,1,19,5,17,10,3};

Functional Approach

In[73]:=
functional=Split[test,#2!=10&]
Out[73]=
{{14,19,19,17,15,11},{10,9,19,8,18,11,9,5},{10,15,2,12,15,12,18,1,2,9,2,13,12,


20,6,4,2,4,1,5,12,13,4,12,11,16,1,1,6,13,12},{10,7,5,18,2},{10},{10,13,

20},{10,3,8,12,16,2,12,12,6,17,17,20,0,7,1,11,3,0,13,0,16,14,20,4,12,15,3,

    18,18,1,12,12,0,13,20,5,15,8,17},{10,9,14,1,19,5,17},{10,3}}

Pattern Matching Approach

In[70]:=
rr1={{x___,10,y___,10,z___}:>{x,{10,y},10,z}}
Out[70]=
{{x___,10,y___,10,z___}\[RuleDelayed]{x,{10,y},10,z}}
In[132]:=
rr2={x__,y__List,z__?((Head[#]=!=List)&)}:>{{x},y,{z}}
Out[132]=
{x__,y__List,z__?(Head[#1]=!=List&)}\[RuleDelayed]{{x},y,{z}}
In[133]:=
test//.rr1
Out[133]=
{14,19,19,17,15,

11,{10,9,19,8,18,11,9,5},{10,15,2,12,15,12,18,1,2,9,2,13,12,20,6,4,2,4,1,5,


12,13,4,12,11,16,1,1,6,13,12},{10,7,5,18,2},{10},{10,13,20},{10,3,8,12,16,


2,12,12,6,17,17,20,0,7,1,11,3,0,13,0,16,14,20,4,12,15,3,18,18,1,12,12,0,

    13,20,5,15,8,17},{10,9,14,1,19,5,17},10,3}
In[134]:=
patternmatching=(test//.rr1)/.rr2
Out[134]=
{{14,19,19,17,15,11},{10,9,19,8,18,11,9,5},{10,15,2,12,15,12,18,1,2,9,2,13,12,


20,6,4,2,4,1,5,12,13,4,12,11,16,1,1,6,13,12},{10,7,5,18,2},{10},{10,13,

20},{10,3,8,12,16,2,12,12,6,17,17,20,0,7,1,11,3,0,13,0,16,14,20,4,12,15,3,

    18,18,1,12,12,0,13,20,5,15,8,17},{10,9,14,1,19,5,17},{10,3}}

Make Sure We Get The Same Answer

In[135]:=
functional==patternmatching
Out[135]=
True



  • Prev by Date: Re: Partition List
  • Next by Date: Integrate[x^x,x]??
  • Previous by thread: Re: Partition List
  • Next by thread: Re: Partition List