[Jprogramming] Selective verb application
'Pascal Jasmin' via Programming
programming at jsoftware.com
Thu Jan 16 15:58:12 UTC 2020
a generic approach,
([: (0 ~: 3 | i.@:#@{.)`]} ] ,:~ >: ) i.20
1 1 2 4 4 5 7 7 8 10 10 11 13 13 14 16 16 17 19 19
can be turned into conjunction where u = verb you want to apply, n is the interval
fornth1 =: 2 : '([: (0 ~: n | i.@:#@{.)`]} ] ,:~ u )'
except your desired result does not actually literally apply just nth element. Rather, in your example, the 0th and 2nd indexes are repeatedly incremented. If instead just the nth elements are to be processed then the conjunction is:
fornth =: 2 : '([: ((n-1) = n | i.@:#@{.)`]} ] ,: u )'
>: fornth 3 i.20
0 1 3 3 4 6 6 7 9 9 10 12 12 13 15 15 16 18 18 19
>: fornth 3 i.20
On Wednesday, January 15, 2020, 09:30:38 p.m. EST, Skip Cave <skip at caveconsulting.com> wrote:
How does one apply a monadic verb repetitively to every nth element of a
one1-dimentional array?
For example:
]a=.i.20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
n=.3
NB. Design u to increment every nth integer in a:
u=.??:<??
n u a
1 1 2 4 4 5 7 7 8 10 10 11 13 13 14 16 16 17 19 19
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list