Re: Sorting of two interdependent sequences

new topic     » goto parent     » topic index » view thread      » older message » newer message
SnakeCharmer said...

There are two sequences, first for names and second for numbers. I need to sort numbers, but names should be sorted as appropriate.

Example (in case I badly explained in English):

Names = {"Army of Lovers", "Boney M.", "C. C. Catch", "Dschinghis Khan"}
Numbers = {1987, 1975, 1985, 1979}

After sorting:

Numbers = {1975, 1979, 1985, 1987}
Names = {"Boney M.", "Dschinghis Khan", "C. C. Catch", "Army of Lovers"}

{1987, 1975, 1985, 1979}
convert it to
{1987.1, 1975.2, 1985.3, 1979.4}
Sort it to
{1975.2, 1979.4, 1985.3, 1987.1}
extract a new sequence from this
{0.2, 0.4, 0.3, 0.1}
multiply by 10 to
{2, 4 ,3, 1}
Use this sequence of integers to extract the elements of the other sequence
extract the 2nd, then 4th then 3rd then 1st from
{"Army of Lovers", "Boney M.", "C. C. Catch", "Dschinghis Khan"}
and you get
{"Boney M.", "Dschinghis Khan", "C. C. Catch", "Army of Lovers" }

If your intial integer sequence (of years) is long - say 73 elements, you can add 0.01, 0.02,.... etc to 0.73 and so on and so forth.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu