As your examples illustrate, this is something of an underspecified problem.
But let's try a few things...
First, there's your basic i. which gets us a sequence:
i.1+14
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
And adding step 3 means taking fewer steps and making them longer
3*i.<.1+14%3
0 3 6 9 12
And we can of course add our starting point back in:
5+3*i.<.1+14%3
5 8 11 14 17
Meanwhile, without step, we can make a dyad to give us all integers in a range:
thru=: <. + i.@(+ *)@-~
5 thru 19
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
19 thru 5
19 18 17 16 15 14 13 12 11 10 9 8 7 6 5
With step, what would this look like?
(#~ 0= 3|]) 5 thru 19
6 9 12 15 18
(#~ 0= 3|5-~]) 5 thru 19
5 8 11 14 17
(#~ 0= 3|19-~]) 5 thru 19
7 10 13 16 19
Let's pick the second one (since it matches an example you gave) and
parameterize that. Specifically, let's declare our arguments like
this:
step stepThrough start,limit
('step', 'start' and 'limit' are all single integers here, and
'stepThrough' will be our verb)
I can't see any non-verbose ways of making this tacit, so:
stepThrough=:dyad define
'start diff'=. -/\ y
start-(*diff)*x*i.<.1+x%~|diff
)
3 stepThrough 5 19
5 8 11 14 17
3 stepThrough 19 5
19 16 13 10 7
Does the implementation seem a bit arbitrary? Well... it should. After
all, we arbitrarily picked from one of several possible mechanisms
which matched the description.
But I hope this helps. (And, I hope email transport doesn't reformat
what I've written.)
Thanks,
--
Raul
On Sun, Mar 29, 2020 at 5:52 AM 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm