MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

sorting problem

  • To: mathgroup at
  • Subject: [mg130633] sorting problem
  • From: S <dsalman96 at>
  • Date: Sun, 28 Apr 2013 00:57:59 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:


I need to sort a list in increasing magnitude. If two elements in the list are the same, the element which appears EARLIER in the list should appear first. Finally, I need the indices of the sorted list according to the above two rules.

e.g. for input 
distances = {0, Sqrt[2], Sqrt[2], 0, 0, Sqrt[2], 2, Sqrt[2]}
I need the answer to be 

I tried the following commands:

distances = {0, Sqrt[2], Sqrt[2], 0, 0, Sqrt[2], 2, Sqrt[2]}
Sorteddistances = Sort[distances, Less]
k = Ordering[distances]

I get output k={1, 4, 5, 7, 2, 3, 6, 8}.

However, I want the output k={1,4,5,2,3,6,8,7}

Can someone please suggest how to do this.



  • Prev by Date: Re: Export to PDF outline issues
  • Next by Date: combinations problem
  • Previous by thread: Re: Convolve : Different Looking Results
  • Next by thread: Re: sorting problem