Post Reply 
How to sort two lists? Sort distance
12-03-2019, 05:02 PM
Post: #17
RE: How to sort two lists?
(12-03-2019 10:24 AM)ailoher Wrote:  What I would need is to sort the elements from a list with respect to their distance to an element outside the list. Is there any way to do so?

Here is a CAS program that should do what you want, if I've correctly understood it:

Code:
#cas
sortd(li,ref):=
BEGIN
 return sort(li,(x,y)->abs(x-ref)<abs(y-ref));
END;
#end

sortd({2,3,6,8,5,9},5) returns {5,6,3,2,8,9}
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
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? - Tyann - 05-02-2016, 05:32 AM
RE: How to sort two lists? - Tyann - 05-02-2016, 10:35 AM
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? - 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)