MathGroup Archive 1999

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

Search the Archive

Re: Re: Select in Math.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16611] Re: [mg16518] Re: Select in Math.
  • From: "Wolf, Hartmut" <hwolf at debis.com>
  • Date: Fri, 19 Mar 1999 12:53:44 -0500
  • Organization: debis Systemhaus
  • References: <199903160859.DAA09380@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

> 
> In a message dated 3/8/99 6:43:38 PM, kewjoi at hixnet.co.za writes:
> 
> >My question is how can I extract (select) list of lists in increasing
> >order?
> >For example:
> >In[2]:=list={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}}
> >Out[2]={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}}
> >
> >I 'd like to obtain only the parts in increased order, therefore the
> >result should be :
> >Out[3]={{1,2,3,4},{5},{6,7}}
> >I did try (Cases, Select, and Extract) but definitely not in proper way.
> >
> 
> Eugene,
> 
What is your Problem?

Another guess is illustrated by the procedure:

In[1]:= list={{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}}
Out[1]= {{{1,2,3,4},{1,2,4,3}},{{2,3,1},{5}},{6,7}}

Picking out the sublists at the lowest level:

In[2]:= Flatten at MapIndexed[subList, list, {-2}]
Out[2]=

{subList[{1,2,3,4},{1,1}],subList[{1,2,4,3},{1,2}],subList[{2,3,1},{2,1}],
  subList[{5},{2,2}],subList[{6,7},{3}]}

Removing the clutter:

In[3]:= l= %/. subList[x_,_]:>x
Out[3]= {{1,2,3,4},{1,2,4,3},{2,3,1},{5},{6,7}}

far (and dropping emptied lists):

Defining

In[4]:= f[x_, y_] := If[(c=Complement[y,Flatten[x]])
=!={},Append[x,c],x]
In[5]:= akindofUniqueLists[ll_]:= 
  Module[{subList},
    Block[{fl=Flatten at MapIndexed[g, ll, {-2}] /. subList[x_,_]:>x},
      Fold[f,{},fl]  ]]

In[6]:= r0=akindofUniqueLists[list]
Out[6]= {{1,2,3,4},{5},{6,7}}

If that procedure really does what you want in general, you may decide
looking at different test cases:

In[7]:= l1={{{5},{{},{4,3}}},{{{2,1},{2,3,4}},{2,5}},{}};
In[8]:= r1=akindofUniqueLists[l1]
Out[8]= {{5},{3,4},{1,2}}

In[9]:= l2={{{{{1},{1,2}},{1,2,3}},{1,2,3,4}},{0}}
In[10]:= r2=akindofUniqueLists[l2]
Out[10]= {{1},{2},{3},{4},{0}}

If you want your results sorted, then do that

In[11]:= p= #1[[1]] < #2[[1]]&;

In[12]:= Sort[r0,p]
Out[12]= {{1,2,3,4},{5},{6,7}}

In[13]:= Sort[r1, p]
Out[13]= {{1,2},{3,4},{5}}

In[14]:= Sort[r2, p]
Out[14]= {{0},{1},{2},{3},{4}}

---Hartmut
__________________________________________________
Hartmut Wold, debis Systemhaus, Darmstadt, Germany



  • Prev by Date: Re: An open letter
  • Next by Date: Re: Importing PostScript files
  • Previous by thread: Re: Select in Math.
  • Next by thread: Re: Select in Math.