How to sort two lists? Sort distance
05-02-2016, 04:00 PM
Post: #13
 Didier Lachieze Senior Member Posts: 1,602 Joined: Dec 2013
RE: How to sort two lists?
(05-02-2016 10:35 AM)Tyann Wrote:  Merci pour vôtre réponse, mais vôtre solution ne convient pas.
Vous triez les 2 listes par odre ascendant. -> {{1,2,3},{15,18,20}}

Moi je veux trier la liste 1 et que la liste 2 suive la liste 1 ->{{1,2,3},{18,20,15}}
J'espére que la nouvelle syntaxe autorise cela.

You sort the two lists in ascending order. -> { {1,2,3 }, { 15,18,20 }}

I want my sort List 1 and List 2 follows the list 1 - > { {1,2,3 }, { 18,20,15 }}
I hope that the new syntax allows this.

Sorry for the misunderstanding. Here is a program doing what you want:

Code:
EXPORT Sortn(list,n) BEGIN   LOCAL li,ma;   ma:=list2mat(list) ;   li:=SORT(MAKELIST(mat2list(col(ma,I)),I,1,colDim(ma)),n);   RETURN MAKELIST(mat2list(col(list2mat(li),I)),I,1,rowDim(ma)); END;

For example:

Sortn({{3,2,1},{15,20,18}},1) -> {{1,2,3},{18,20,15}}

Sortn({{3,2,1},{15,20,18},{32,35,27}},1) -> {{1,2,3},{18,20,15},{27,35,32}}
Sortn({{3,2,1},{15,20,18},{32,35,27}},2) -> {{3,1,2},{15,18,20},{32,27,35}}
Sortn({{3,2,1},{15,20,18},{32,35,27}},3) -> {{1,3,2},{18,15,20},{27,32,35}}
 « Next Oldest | Next Newest »

 Messages In This Thread How to sort two lists? Sort distance - StephenG1CMZ - 04-29-2016, 07:06 PM RE: How to sort two lists? - parisse - 04-29-2016, 07:33 PM RE: How to sort two lists? - primer - 04-29-2016, 09:22 PM RE: How to sort two lists? - StephenG1CMZ - 04-30-2016, 10:04 AM RE: How to sort two lists? - parisse - 05-02-2016, 05:44 AM RE: How to sort two lists? - cyrille de brébisson - 05-02-2016, 04:56 AM RE: How to sort two lists? - Tyann - 05-02-2016, 05:32 AM RE: How to sort two lists? - Didier Lachieze - 05-02-2016, 06:57 AM RE: How to sort two lists? - Tyann - 05-02-2016, 10:35 AM RE: How to sort two lists? - Didier Lachieze - 05-02-2016 04:00 PM RE: How to sort two lists? - Tyann - 05-02-2016, 05:10 PM RE: How to sort two lists? - DrD - 05-02-2016, 11:11 AM RE: How to sort two lists? - StephenG1CMZ - 05-02-2016, 12:11 PM RE: How to sort two lists? - cyrille de brébisson - 05-02-2016, 03:34 PM RE: How to sort two lists? - ailoher - 12-03-2019, 10:24 AM RE: How to sort two lists? - Didier Lachieze - 12-03-2019, 05:02 PM RE: How to sort two lists? - StephenG1CMZ - 12-03-2019, 04:43 PM RE: How to sort two lists? - Albert Chan - 12-03-2019, 06:00 PM RE: How to sort two lists? - StephenG1CMZ - 12-03-2019, 07:30 PM RE: How to sort two lists? - ailoher - 12-05-2019, 06:55 PM RE: How to sort two lists? - StephenG1CMZ - 12-06-2019, 12:30 AM

User(s) browsing this thread: 1 Guest(s)