the step is calculated rather than given
you’d need to preprocess the argument(s)

Am 02.04.20 um 01:26 schrieb Fraser Jackson:
No one has mentioned the simple function
load 'stats/base'
steps 5 19 14
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
steps 5 9 8
5 5.5 6 6.5 7 7.5 8 8.5 9
steps _3 10 13
_3 _2 _1 0 1 2 3 4 5 6 7 8 9 10
steps 4.25 8.75 9
4.25 4.75 5.25 5.75 6.25 6.75 7.25 7.75 8.25 8.75
steps 9 4 5
9 8 7 6 5 4
Also useful for a wide variety of other cases


Sent from Mail for Windows 10

From: Don Kelly
Sent: Thursday, April 2, 2020 10:27 AM
To: [email protected]
Subject: Re: [Jprogramming] generate integers from a to be with a step

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

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


--
----------------------
mail written using NEO
neo-layout.org

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

Reply via email to