Hallo, IOhannes m zmoelnig hat gesagt: // IOhannes m zmoelnig wrote:
well, the subject of the mail was about "ordered" numbers, so i thought about sorting arbitrary numbers, not a fixed set. if you have a fixed set of numbers and want to do a mapping between those, your solution is surely the preferred way to go.
However if you use the old zexy sort, you can get at the indices using the table-map approach as well. If you have four numbers in a vector x, that is x[0],x[1],x[2],x[3], and if you then sort this, you are in fact looking for the position, that each element in the sorted list, had in the unsorted input vector x.
A very simple approach would be to store vector x into a table, then for each element of the result list, look for the position of this element by walking through [table x], compare every x[i] for equality with the current output element, and store its "i"ndex.
Attached patch illustrates this. It's a bit complicated, uses [list] again but only to do what [drip] does. For simplicity table length is assumend to be 4, however with resizing tables etc. it could be made to work for a changing number of input floats as well.
Known bug: It fails, if the same input number occurs twice or more.
Frank Barknecht _ ______footils.org_ __goto10.org__