Re: Sorting coefficients

• To: mathgroup at smc.vnet.net
• Subject: [mg124059] Re: Sorting coefficients
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sat, 7 Jan 2012 05:22:56 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201201060914.EAA26796@smc.vnet.net>

```On 6 Jan 2012, at 10:14, Chris Young 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
> cy56 at comcast.net
>
>
> In[1043]:= Prepend[
> Table[{Re, Im}[ E^(k (2 \[Pi])/6 I)] // Through, {k, 0, 5}], {0, 0}]
>
> Out[1043]= {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}, {-(1/2), Sqrt[3]/
>  2}, {-1, 0}, {-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}}
>
> In[1046]:= Sort[%1043, #1[[2]] < #2[[2]] &]
>
> Out[1046]= {{1/2, -(Sqrt[3]/2)}, {-(1/2), -(Sqrt[3]/2)}, {-1, 0}, {1,
>  0}, {0, 0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}
>
> In[1073]:= Sort[%1046, #1[[2]] < #2[[2]] &]
>
> Out[1073]= {{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {0, 0}, {1,
>  0}, {-1, 0}, {1/2, Sqrt[3]/2}, {-(1/2), Sqrt[3]/2}}
>
>

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

ls1 =
Sort[ls, Which[#1[[2]] < #2[[2]],
True, #1[[2]] == #2[[2]], #1[[1]] < #2[[1]], True, False] &]

{{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-1, 0}, {0,
0}, {1, 0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}

Graphics[MapIndexed[{Text[First[#2], #1]} &, ls1]]

?

Andrzej Kozlowski

```

• Prev by Date: Re: Sorting coefficients
• Next by Date: Re: DirectoryStack[] not showing top directory stack item
• Previous by thread: Re: Sorting coefficients
• Next by thread: Re: Sorting coefficients