Thanks, "range' is neat. The added 1 in ... 3{.y,1 got me for a bit
but I see that it allows range 5 13 as well as 5 13 1
I must open up more of the library even if it spoils my fun.
Don
On 2020-04-04 3:15 p.m., chris burke wrote:
numeric has both:
steps 5 13 4
5 7 9 11 13
range
numeric has both:
steps 5 13 4
5 7 9 11 13
range 5 13 2
5 7 9 11 13
On Sat, Apr 4, 2020 at 2:26 PM Don Kelly wrote:
>
> However, as Hauke Rehr has indicated, the step size is given in the
> original problem while the method you suggest is given the number of
> steps in the range. There is
However, as Hauke Rehr has indicated, the step size is given in the
original problem while the method you suggest is given the number of
steps in the range. There is a big difference.
Don
On 2020-04-04 2:59 a.m., Mario C wrote:
I prefer
load 'numeric'
steps 5 9 8
etc.
The definitions of
I prefer
load 'numeric'
steps 5 9 8
etc.
The definitions of steps in 'stats/base' and 'numeric' are identical.
Mario
--
For information about J forums see http://www.jsoftware.com/forums.htm
: [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 differe
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: programm...@jsoftware.com
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
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
If you can keep the general exclusive nature of i. then first function is
easier
5 ([ + i.@-~) 20
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
then
steppedinterval =: ([ + i.@-~)/ : (-@[ {.\ ([ + i.@-~)/@]) NB. monadic = step
1
3 steppedinterval 5 20
5 8 11 14 17
On Sunday, March 29,
I do apologise to all involved:
There was an inexcusable bug in the display of the test data
at the end of my script.
Verb rt in my script has been fixed, and consequently
the display of time/space data does show a completely
different picture now.
My versions using ^: are actually significantly
...a bugfix is in the works
there is a horrible bug in the display of the testing table
--
For information about J forums see http://www.jsoftware.com/forums.htm
Have I missed the Fold step?
--
(B=)
--
For information about J forums see http://www.jsoftware.com/forums.htm
Yet anotherone featuring ^: ...
]JVERSION
Engine: j807/j32/windows
Release-e: commercial/2019-11-04T10:14:12
Library: 8.07.26
Qt IDE: 1.7.9s/5.9.6
Platform: Win 32
NB. steps from a to b, using ^:
step=: fst=: 0&{
endv=: snd=: 1&{
srtv=: trd=: 2&{
tail=: {:
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
I have used this pair for a very long time,
to=. [ + 1 i.@+ <.@-~
inc=. (%&) ((<,'&.')`) (`:6) NB. replacing <'&.' to make it "future proof"
0 to 10
0 1 2 3 4 5 6 7 8 9 10
0 to (10 inc) 100
0 10 20 30 40 50 60 70 80 90 100
0j2 to (0.1j_0.2 inc) 1j0
0j2 0.1j1.8 0.2j1.6 0.3j1.4
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
5+3*i.5
5 8 11 14 17
On 03/29/2020 05:52 AM, 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
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
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
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
19 matches
Mail list logo