I like this and find your approach to thru interesting as it works both
ways 5 thru 19 and 19 thru 5. A 'one way' approach could be this
thru2=. }. [:i.>:
5 thru2 19
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
some time difference but no space difference
(100)6!:2 '5 thru2 200'
1.117e_6
(100)6!:2 '5 thru 200'
1.44e_6
reverse
|. 5 thru2 19
19 18 17 16 15 14 13 12 11 10 9 8 7 6 5
Don
On 2020-03-29 7:34 a.m., Raul Miller wrote:
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,
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm