Hi -

I'm working with selecting sequential items from a vector given a starting
and an ending point as a pair of integers.  If we assume we always get the
pair as (lesser, greater), something like this suffices:

   seq=: {. + [: i. [: >: -~/
   seq 3 7
3 4 5 6 7

However, if our assumption about the order of our points is violated, we
get nonsense:

   seq 7 3
7 8 9

Just for robustness, how could we write a version of "seq" that would
return the sequence in reverse order in this latter case, i.e. give the
proper sequence from seven to three: 7 6 5 4 3 ?

I generalized the "seq" verb to remove the ordering assumption: my idea was
to generate the ascending sequence, then flip it if >/y is true.  I tried
this with "agenda" but am not sure how to get it to work on one thing - the
ascending vector - on the basis of comparison of another thing - the pair
of integers.

I did achieve this using the "power" conjunction:

   seq=: 3 : '|.^:(>/y)](<./ + [: i. [: >: >./ - <./) y'
   seq 3 7
3 4 5 6 7
   seq 7 3
7 6 5 4 3

Does anyone have any ideas for a more elegant, preferably tacit, solution?

Thanks,

Devon
-- 

Devon McCormick, CFA

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

Reply via email to