Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

sorting a nested list of 4-tuples

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120328] sorting a nested list of 4-tuples
  • From: Luis Valero <luis.valero at mac.com>
  • Date: Tue, 19 Jul 2011 06:55:53 -0400 (EDT)

Dear Sirs,

I want to sort a list of 4-tuples of real numbers, so that, the second 4-tuple has minimum distance to the first, the third, selected from the rest, ha minimum distance to the second, and so on.

The distance is the euclidean distance, calculated with the first two elements of each 4-tuple. 

I have defined a function that work:

orderedList[list_] := Module[{nearest}, 
	Flatten[ Nest[{
   	    Append[ #[[1]] , nearest = Flatten @@ Nearest[ Map[ Rule[ #[[{1, 2}]], #] &, #[[2]] ], Last[ #[[1]] ] [[{1, 2}]], 1] ],
    	    Delete[ #[[2]], Position[ #[[2]], nearest ] ]  } &, { {list[[1]] }, Delete[ list, 1 ] }, Length[ list ] - 2], 1] ];


but I need to improve the temporal efficiency 

Thank you 




  • Prev by Date: Re: Replace, test question
  • Next by Date: Re: Solve never calls Equal?
  • Previous by thread: Re: Transforming an expression to publication form
  • Next by thread: Re: sorting a nested list of 4-tuples