I would write it from right to left:
s=:2
e=:5
i=:0.25
s + i * i. 1 + (e-s) % i
x=:2 5
y=:i
--/x
3
y%~--/x
12
(0{x)+y*i.>:y%~--/x
2 2.25 2.5 2.75 3 3.25 3.5 3.75 4 4.25 4.5 4.75 5
f=: 13 :'(0{x)+y*i.>:y%~--/x'
2 5 f 0.25
2 2.25 2.5 2.75 3 3.25 3.5 3.75 4 4.25 4.5 4.75 5
f
(0 { [) + ] * [: i. [: >: ] %~ [: - [: -/ [
Notice that it cleaned up my act a little. So, what would the optimal code
look like?
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Skip Cave
Sent: Thursday, August 23, 2012 5:08 AM
To: [email protected]
Subject: [Jprogramming] Generating a sequence
I would like to generate a vector sequence of numbers starting from s and
going to e, with increment i here is an explicit function for that:
s + i * i. 1 + (e-s) % i
s =. 2
e =. 5
i =. 0.25
s + i * i. 1 +(e-s) % i
2 2.25 2.5 2.75 3 3.25 3.5 3.75 4 4.25 4.5 4.75 5
what would the tacit form of the sequence verb look like, if we defined the
dyadic verb seq thus:
(s,e) seq i
--
Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm