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
- Follow-Ups:
- Re: sorting a nested list of 4-tuples
- From: DrMajorBob <btreat1@austin.rr.com>
- Re: sorting a nested list of 4-tuples
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: sorting a nested list of 4-tuples
- From: Sseziwa Mukasa <mukasa@gmail.com>
- Re: sorting a nested list of 4-tuples
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: sorting a nested list of 4-tuples