as for the trailing 5s:

i: needs to fill with trailing 0s so you intermediately get

_2 _1 0 1 2
_2 0 2 0 0

adding 5 leads to your result


I once wrote this (here adjusted to Ruda’s example)
in case stepping is used really frequently
throughout the code — but there is too much
(two multiplications and one addition on the vector)
happening after cut01 so it’s not worth the effort

NB. say we have y = 4 and want to get 0 0.25 0.5 0.75 1
cut01 =: (% * i.@>:) M.
NB. say we have x = 14 and y = 3 and want to get 0 3 6 9 12
steps =: ([ - |~) ([ * cut01@%) ]
NB. say we have x = 5 19 and y = 3 want to get 5 8 11 14 17
stepThrough =: {.@[ + <:@+:@</@[ * |@-/@[ steps ]



Am 29.03.20 um 12:39 schrieb 'Michael Day' via Programming:
I was thinking that i: with a complex argument would get you there, eg:

     5+i:2 2j2

3 4 5 6 7

3 5 7 5 5   NB. why the trailing 5s?


but bending it to your wishes looks a bit tricky.


I vaguely recalled there was a utility verb, "steps."  I've found it in various addons;

I think it's in one of the standard libraries, too:


    steps=: {. + (1&{ - {.) * (i.@>: % ])@{:
    steps 3 7 2
3 5 7
    steps 3 7 3
3 4.33333 5.66667 7


I see someone else has just posted,  but I'll send this anyway,  having spent a few minutes on it!


Cheers,


Mike


On 29/03/2020 10:52, Rudolf Sykora 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



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

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

Reply via email to