Rudolf Sykora <[email protected]> wrote:
> Dear all,
>
>
> how do you usually generate a sequence of integers from 'a' to 'b' with
> a step 's'?
>
> If I ignore the step, yesterday I wrote
>
> interval=.{.+(i. @ >: @ ({:-{.))
> interval 5 19
> 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>
> but that seems overly complicated...
> Then I can include the step in this way
>
> _3 {.\ interval 5 19
> 5 8 11 14 17
>
> Putting the two parts together would make it even more complicated.
> There must be a better way...
>
>
> Thanks
> Ruda
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
a=: 5
b=: 20
k=: 3
a+k*i.(b-a)<.@%k
5 8 11 14 17
The above generates first generates 0, k, 2*k, ..., n*k in the range [0,b-a]
and then just shifts up by a.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm