Friendly Challenge 2: sort by column

• To: mathgroup at smc.vnet.net
• Subject: [mg35005] Friendly Challenge 2: sort by column
• From: gleam at flashmail.com ("Mr. Wizard")
• Date: Wed, 19 Jun 2002 05:52:39 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```	Once again, I am posting a friendly challenge with the hope of
provoking thought and encouraging creativity.  This time, the
challenge is to write the "best" sort-by-column function you can.

Once again, have already written several such functions, which I will
delay posting these until a number of responses are received.  This is
not because I think I am some kind of Mathematica "guru" will all the
right answers, but rather to prevent my methods from influencing
others.

Once again, though I am setting guidelines for this challenge, I will
not be pronouncing some final judgement of a winning algorithm.  I
would much prefer that this challenge induces a good discussion of the
merits of various approaches and methods.

Description:

The function shall take two arguments: (1) a rectangular matrix and
(1) the number of a column in (1).

The function shall sort the rows of (1) according primarily to the
element in the column specified by (2).

The function shall not effect sub-elements in a three dimensional
matrix.

Example:

a = {{77,27,57,53},
{72,21,40,27},
{96,76,87,27},
{61,97,93,71},
{43,80,21,87}}

In:= f[a, 3]

Out= {{43,80,21,87},
{72,21,40,27},
{77,27,57,53},
{96,76,87,27},
{61,97,93,71}}

You may handle duplicates in the sort column as you see fit, but
please explain it for the rest of us, and be prepared give support for
this as you would all other behaviors of your function.

Be creative, have fun, and good luck!

Paul

```

• Prev by Date: RE: Colors
• Next by Date: Re: RE: Experimental`FileBrowse
• Previous by thread: Convolution problem
• Next by thread: Re: Friendly Challenge 2: sort by column