How sort list?




---- OriginalMessage ----
From: aleksas.domarkas at post.skynet.lt
To: "reyssat" <eric.reyssat at math.unicaen.fr>
Sent: 2010-07-07 12:04
Subject: Ats.: Re: [Maxima] How sort list?



---- OriginalMessage ----
From: "reyssat" <eric.reyssat at math.unicaen.fr>
To: aleksas.domarkas at post.skynet.lt
CC: maxima at math.utexas.edu
Sent: 2010-07-07 08:59
Subject: Re: [Maxima] How sort list?

aleksas.domarkas at post.skynet.lt a ?crit :
> Let
> S:[[5,1],[4,2],[3,5],[2,3],[1,4]]
> I need a function f, such that
> sort(S,f)
> get
> [[1,4],[4,2],[2,3],[3,5],[5,1]]

I think that
- either you need to solve some general sorting problem, then you have
to precise it, and this gives you a clue to what the function f might be
- or you just need to treat this particular numerical example (I can't
imagine why) and you may just construct an ad hoc function, for instance :
g(x):=if x=[1,4] then 1 else if x=[4,2] then 2 else if x=[2,3] then 3
else if x=[3,5] then 4 else if x=[5,1] then 5 else 0 ;
f(x,y):=g(x)<g(y);

Eric
> ------------------------------------------------------------------------
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>

This is only example. Other example:
I ned
[[7,1],[10,9],[5,7],[4,2],[6,8],[1,6],[9,4],[3,5],[8,10],[2,3]]
transform to
[[1,6],[6,8],[8,10],[10,9],[9,4],[4,2],[2,3],[3,5],[5,7],[7,1]]
 
This lists are solutions of Hamiltonian Cycle problem or Travelling Salesman Problem
see http://www.math.jmu.edu/~lucassk/Papers/determinant.pdf
 
Thank          Aleksas