I have task for which I couldn't find a solution.

Suppose we have some indexes which relate to some data.
Now I have vector which describe which indexes to keep and which to remove.

For example:  pat =: 4 _3 2 _1

Positive value - tell how many indexes to keep, negative to remove. So the pat is telling that I need to keep 4 first indexes then remove 3 next, keep another 2, remove 1, keep 4, remove 3 and so on. I need function that for giving index give me new index after applying such pattern. Indexes of removed items - is index of next keeped item.

So applying this function to i.20 and pat I should see:
OLD: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
NEW: 0 1 2 3 4 4 4 4 5 6 6  7  8  9  10 10 10 10 11 12

Another function will make inverse calculation - for each value from NEW give the biggest value from OLD.

I wonder is it posible to achieve whithout precalculating vector of NEW indexes, just by calculating new value from given pat and old index?

Thanks in advance,
Mikl

--
Mikl
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to