Re: My first program: sublime (reverse of "extract" function)
- Posted by SocIoDim May 19, 2013
- 2417 views
I think I get it. Your example can still be implemented as:
sequence InputData = {0.01, 0.05, 0.08, 0.03, 0.02} sequence OutputData = 1 - InputData[2..$]
NO
But I think your point is clear - you don't want to merely use your sorted input data for a task and then reuse the unsorted version later. You don't want to just sort the output data either. You need to sort the input data for a task, then "unsort" the output data such that the each element of the output data is in the same position as the corresponding element in the original unsorted input data.
YES
If every element is unique in the input data, and every element is unique in the output data, then you could just use mapping(). But that probably isn't true.
It isn't true, otherwise it would have been much easier. The second "find" in my function is designed to avoid the associated problems.
P.S. I've been thinking how best to implement this feature: simple or optimal. This is the easiest and most non-optimal option. There have been other attempts.
I'd go with optimal.
I think, most optimal way is implement my own sorting function, that will output the sorted data and unsorted indexes. I wrote such function, but erase, because it turned ugly. This is wrong way: replacing the standard language features. This is called the invention of bicycles. Other attempts have been associated with disposal of the second "find".
There was an idea to look unsorted data in a sorted array. This would allow to use a binary search. But it turned out unnecessary complexity of the algorithm due to processing conflicts associated with identical elements. This is only one of the problems. I'm not a bad analyst really. Deceptive simpleness of this algorithm was hard-won in a few days.