       Re: Sorting coefficients

• To: mathgroup at smc.vnet.net
• Subject: [mg124050] Re: Sorting coefficients
• From: "jf.alcover" <jf.alcover at gmail.com>
• Date: Sat, 7 Jan 2012 05:19:49 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <je6e2k\$q6b\$1@smc.vnet.net>

```On 6 jan, 10:15, Chris Young <c... at comcast.net> wrote:
> I'm trying to get my points sorted first by rows first. But I'm having
> trouble figuring out how to do the kind of double sorting I need with
> Sort. SortBy seems very hard to figure out and I'm not sure if it's
> what I need here.
>
> I've just got a hexagonal layout of point coordinates, with another one
> on the origin, and I'm trying to sort everything from lower left to
> upper right. I.e., the usual ordering of going through the bottom row
> from left to right, then through the middle row from left to right, etc.
>
> Any help appreciated.
>
> Chris Young
> c... at comcast.net
>
> In:= Prepend[
>  Table[{Re, Im}[ E^(k (2 \[Pi])/6 I)] // Through, {k, 0, 5}], {0, 0}]
>
> Out= {{0, 0}, {1, 0}, {1/2, Sqrt/2}, {-(1/2), Sqrt/
>   2}, {-1, 0}, {-(1/2), -(Sqrt/2)}, {1/2, -(Sqrt/2)}}
>
> In:= Sort[%1043, #1[] < #2[] &]
>
> Out= {{1/2, -(Sqrt/2)}, {-(1/2), -(Sqrt/2)}, {-1, 0}, {1,
>   0}, {0, 0}, {-(1/2), Sqrt/2}, {1/2, Sqrt/2}}
>
> In:= Sort[%1046, #1[] < #2[] &]
>
> Out= {{-(1/2), -(Sqrt/2)}, {1/2, -(Sqrt/2)}, {0, 0}, {1,
>   0}, {-1, 0}, {1/2, Sqrt/2}, {-(1/2), Sqrt/2}}

My suggestion :

In:=  t=Prepend[Table[{Re,Im}[E^(k (2 \[Pi])/6 I)]//Through,{k,
0,5}],{0,0}];

In:= myLess[{x1_,y1_},{x2_,y2_}]:=Which[y1<y2, True, y1>y2, False,
True,
Which[x1<x2, True, x1>x2, False, True, False]]

In:=  Sort[t,myLess]
Out= {{-(1/2), -(Sqrt/2)}, {1/2, -(Sqrt/2)}, {-1, 0}, {0, 0},
{1, 0}, {-(1/2), Sqrt/2},
{1/2, Sqrt/2}}

hth

```

• Prev by Date: Prevent synchronizing a certain symbol between main and parallel
• Next by Date: Re: ParametricPlot3D vs Reduce
• Previous by thread: Re: Sorting coefficients
• Next by thread: Sorting point-arrays by rows and columns, cont.