Re: I don't know how to ....

• To: mathgroup at smc.vnet.net
• Subject: [mg2425] Re: I don't know how to ....
• From: rubin at msu.edu (Paul A. Rubin)
• Date: Sun, 5 Nov 1995 16:06:51 -0500
• Organization: Michigan State University

```In article <471hgv\$gb3 at ralph.vnet.net>,
bientin at cli.di.unipi.it (Paolo Bientinesi) wrote:
->Hi all,
->here's my problem:
->I need  a function that takea as input a list of pairs;
->the first element of every pair is a list, the second one is an integer;
->I want the function to calculate thhe
->biggest integer and to give as output the corresponding list.
->
->I didn't succeeded.
->thanks
->Paul DJ a
->
->
->
In[1]:=  Clear[f];
f[ x:{{_List, _Integer}..} ] := Sort[ Reverse /@ x ][[-1, 2]]
In[2]:=  xx = {{{a,b,c}, 5}, {{d,e}, -3}, {{f,g,h,i}, 7}};
In[3]:=  f[xx]
Out[3]=  {f, g, h, i}

This is a trifle inefficient if your list is long, since it sorts the
entire list (rather than just isolating the largest integer).  For long
lists, a partial bubble sort might be better.  Also, I've ignored the
question of resolving ties for largest integer; you might prefer to print
all lists whose integers are tied (assuming ties can occur in your
context).

Paul Rubin

**************************************************************************
* Paul A. Rubin                                  Phone: (517) 432-3509   *
* Department of Management                       Fax:   (517) 432-1111   *
* Eli Broad Graduate School of Management        Net:   RUBIN at MSU.EDU    *
* Michigan State University                                              *
* East Lansing, MI  48824-1122  (USA)                                    *
**************************************************************************
Mathematicians are like Frenchmen:  whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different.                                    J. W. v. GOETHE

```

• Prev by Date: Re: Self referring function
• Next by Date: RE: Calling BarChart function from Math-Link program
• Previous by thread: Re: Self referring function
• Next by thread: Re: I don't know how to ....