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=: {:
pstepHugo=: (2&}.) @:((] , (0&$`({. + {:))@.((endv - step) >: {:))^:_) @: ([
, |.@:])
3 pstepHugo 5 19
5 8 11 14 17
monadisch=: [ , |.@:]
friggin =: [: <. step %~ endv - srtv
pstepSusi=: (2&}.) @:((] , (step + tail))^:friggin) @: monadisch
3 pstepSusi 5 19
5 8 11 14 17
3 pstepSusi 5 20
5 8 11 14 17 20
FROMTO=: 5 19
STEP=:3
]hres=: ({.FROMTO) + STEP * i. >: <. STEP %~ -/|.FROMTO
5 8 11 14 17
assert 5 8 11 14 17-: hres
NB. - evaluation -
ts=: 6!:2, 7!:2@] NB. Phrases 14A
ft=: 12j6 12&":
rt=: {. ([ , <.@(100&*)@:([ %"1 ])) }.
STEP=: 3
FROMTO=: 17 17e3
o=: '({.FROMTO) + STEP * i. >: <. STEP %~ -/|.FROMTO'
a=: 'STEP pstepHugo FROMTO '
b=: 'STEP pstepSusi FROMTO '
NB. - - -
NB. Hauke Rehr JFORUM
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
stepThroughHR =: {.@[ + <:@+:@</@[ * |@-/@[ steps ]
assert 5 8 11 14 17-: 5 19 stepThroughHR 3
hr=: 'FROMTO stepThroughHR STEP NB. H.R. '
NB. - - -
NB. Raul Miller JFORUM
stepThroughRM=:dyad define
'start diff'=. -/\ y
start-(*diff)*x*i.<.1+x%~|diff
)
assert 5 8 11 14 17-: 5 19 stepThroughRM~ 3
rm=:' STEP stepThroughRM FROMTO NB. R.M.'
NB. - - -
NB. Jose Mario Quintana JFORUM
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
5 to (3 inc) 19
5 8 11 14 17
assert 5 8 11 14 17-: 5 to (3 inc) 19
jmq=: '({.FROMTO) to (STEP inc) ({:FROMTO) NB. JMQ'
NB. - - -
NB. Rudolf Sykora JFORUM
interval=.{.+(i. @ >: @ ({:-{.))
assert 5 8 11 14 17-: _3 {.\ interval 5 19
rs=: '(-STEP) {.\ interval FROMTO NB. R.S. '
NB. Intel Pentium(M) 2.31GHz (Single Core)
( <"0@: rt@: >@:(50&ts each) ,"1 0 ] ) a;b;rs;o;hr;rm;jmq
+---------+------+-------------------------------------------------+
|0.0821469|558848|STEP pstepHugo FROMTO |
+---------+------+-------------------------------------------------+
|342 |838 |STEP pstepSusi FROMTO |
+---------+------+-------------------------------------------------+
|6824 |338 |(-STEP) {.\ interval FROMTO NB. R.S. |
+---------+------+-------------------------------------------------+
|146234 |1620 |({.FROMTO) + STEP * i. >: <. STEP %~ -/|.FROMTO|
+---------+------+-------------------------------------------------+
|178579 |422 |FROMTO stepThroughHR STEP NB. H.R. |
+---------+------+-------------------------------------------------+
|87843 |1632 | STEP stepThroughRM FROMTO NB. R.M. |
+---------+------+-------------------------------------------------+
|185472 |550 |({.FROMTO) to (STEP inc) ({:FROMTO) NB. JMQ |
+---------+------+-------------------------------------------------+
NB.
==============================================================================
On 29.03.2020 11: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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm