Re: Recursion
- To: mathgroup at smc.vnet.net
- Subject: [mg25965] Re: Recursion
- From: Leszek Sczaniecki <lsczan at home.com>
- Date: Tue, 14 Nov 2000 03:46:58 -0500 (EST)
- References: <8udm01$egf@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ad.1 Here is one selft-explanatory, I hope, possiblility. In[7]:= cutOff := 9.5 In[8]:= f0[{{x___}, {y___}}, {s_, n_}] := If[n < cutOff, {{x, {s, n}}, {y}}, { {x}, {y, {s, n}}}] In[9]:= f[lst_] := Fold[f0, {{}, {}}, lst] In[10]:= f[{{"poiu", 12}, {"asdfghjkl", 5}, {"qwerty", 18}, {"zxcvbnm", 8}}] Out[10]= {{{"asdfghjkl", 5}, {"zxcvbnm", 8}}, {{"poiu", 12}, {"qwerty", 18}}} In[11]:= f[{}] Out[11]= {{}, {}} Ad. 2 In[12]:= <<DiscreteMath`Combinatorica` In[14]:= Subsets[{}] Out[14]= {{}} In[15]:= Subsets[{1}] Out[15]= {{}, {1}} In[13]:= Subsets[{1, 2}] Out[13]= {{}, {1}, {1, 2}, {2}} Cheers, Leszek Sczaniecki Carlos Baeta Silva wrote: > Hello! > > 1. Someone can tell me how I can define a function (using recursion) that > apllies to a list of this kind: > > {{"poiu", 12},{"asdfghjkl",5},{"qwerty",18},{"zxcvbnm",8}} > > returns { { {"asdfghjkl",5},{"zxcvbnm",8} }, { {"qwerty",18} },{"poiu",12} > } } values <9.5 in one sublist and > in the other. > > And apllies to {} return {{},{}} > > I made this but I can put the sublists inside the empty brackets: > <<...>> > <<...>> > > 2. Other function (using recursion too) that returns the parts of a list: > > aplies to this {} returns {{}} > to {{1}} returns {{1},{}} or {{},{1}} > to {{1,2}} returns {{1,2},{1},{2},{}} > > Thank you very much!