Re: [Jprogramming] Selective verb application

2020-01-16 Thread Raul Miller
Oh, and as you've probably noticed, } and { could be used here, also
(perhaps without using the rank conjunction, if the underlying verb
had a servicable rank).

Thanks,

-- 
Raul

On Thu, Jan 16, 2020 at 9:07 AM Raul Miller  wrote:
>
> Certainly.
>
> But I would be inclined to swap left and right arguments on you (to
> follow the pattern we saw in Roger Hui's post).
>
> Some rather straightforward examples uses ^: or @.  as their core
> mechanism, and rank to spread the operation across the arguments.
>
> This could be done either explicitly or tacitly -- it's that
> straightforward -- though if you get into additional constraints that
> could change the playing field.
>
> Does this give you enough clues to see your way forward? Or are you
> wanting to see canned implementations? (Be aware that canned
> implementation get into questions which you've not yet addressed, like
> "what rank"?)
>
> Thanks,
>
> --
> Raul
>
> On Thu, Jan 16, 2020 at 3:44 AM Skip Cave  wrote:
> >
> > I'm thinking of something along the lines of # (copy)
> >
> > 1 1 1 0 1 0 0 1 0 1 # i.10
> >
> > 0 1 2 4 7 9
> >
> >
> > Only "apply" uses a boolean left argument to define which elements on the
> > right are affected by the verb:
> >
> >
> > 1 1 1 0 1 0 0 1 0 1 (apply -.) 1 1 1 1 1 1 1 1 1 1
> >
> > 0 0 0 1 0 1 1 0 1 0
> >
> > 1 1 1 0 1 0 0 1 0 1 (apply 2&+) 1 1 1 1 1 1 1 1 1 1
> >
> > 3 3 3 1 3 1 1 3 1 3
> >
> > 1 1 1 0 1 0 0 1 0 1 (apply 2&^~) i.10
> >
> > 0 1 4 3 16 5 6 49 8 81
> >
> > Is this possible?
> >
> > Skip Cave
> > Cave Consulting LLC
> >
> >
> > On Thu, Jan 16, 2020 at 2:08 AM Arnab Chakraborty  wrote:
> >
> > > My first idea was to use ^: . But I am unable to get a solution. None of
> > > the posted solutions use ^: either. Just wondering whether ^: can help
> > > here.
> > >
> > > On Thu, 16 Jan 2020, 12:36 'robert therriault' via Programming, <
> > > programm...@jsoftware.com> wrote:
> > >
> > > > It is too late, considering the result is not the one that you 
> > > > requested!
> > > >
> > > > Anyway I would use a numerical approach something like the incorrect one
> > > > that I just posted.
> > > >
> > > > Sheepishly - Cheers, bob
> > > >
> > > > > On Jan 15, 2020, at 23:03, 'robert therriault' via Programming <
> > > > programm...@jsoftware.com> wrote:
> > > > >
> > > > > Hi Skip,
> > > > >
> > > > > A late snowy night silly approach
> > > > >
> > > > >]a=.20#1
> > > > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> > > > >   f1=. *@(3&|)@:i.@:#  NB. mod 3 non-zeros
> > > > >   f1 a
> > > > > 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
> > > > >   f2=. -.@*@(2&|)@:i.@:#  NB. mod 2 zeros
> > > > >   f2 a
> > > > > 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
> > > > >   (f1 *: f2) a  NB. Not-And fork
> > > > > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> > > > >   f=. f1 *: f2  NB. requested result
> > > > >   f a
> > > > > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> > > > >
> > > > > Cheers, bob
> > > > >
> > > > >
> > > > >> On Jan 15, 2020, at 22:29, Skip Cave  wrote:
> > > > >>
> > > > >> ]a=.20#1
> > > > >
> > > > > --
> > > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > > >
> > > > --
> > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-16 Thread 'Pascal Jasmin' via Programming
 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 
 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=.??:http://www.jsoftware.com/forums.htm
  
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-16 Thread Raul Miller
Certainly.

But I would be inclined to swap left and right arguments on you (to
follow the pattern we saw in Roger Hui's post).

Some rather straightforward examples uses ^: or @.  as their core
mechanism, and rank to spread the operation across the arguments.

This could be done either explicitly or tacitly -- it's that
straightforward -- though if you get into additional constraints that
could change the playing field.

Does this give you enough clues to see your way forward? Or are you
wanting to see canned implementations? (Be aware that canned
implementation get into questions which you've not yet addressed, like
"what rank"?)

Thanks,

-- 
Raul

On Thu, Jan 16, 2020 at 3:44 AM Skip Cave  wrote:
>
> I'm thinking of something along the lines of # (copy)
>
> 1 1 1 0 1 0 0 1 0 1 # i.10
>
> 0 1 2 4 7 9
>
>
> Only "apply" uses a boolean left argument to define which elements on the
> right are affected by the verb:
>
>
> 1 1 1 0 1 0 0 1 0 1 (apply -.) 1 1 1 1 1 1 1 1 1 1
>
> 0 0 0 1 0 1 1 0 1 0
>
> 1 1 1 0 1 0 0 1 0 1 (apply 2&+) 1 1 1 1 1 1 1 1 1 1
>
> 3 3 3 1 3 1 1 3 1 3
>
> 1 1 1 0 1 0 0 1 0 1 (apply 2&^~) i.10
>
> 0 1 4 3 16 5 6 49 8 81
>
> Is this possible?
>
> Skip Cave
> Cave Consulting LLC
>
>
> On Thu, Jan 16, 2020 at 2:08 AM Arnab Chakraborty  wrote:
>
> > My first idea was to use ^: . But I am unable to get a solution. None of
> > the posted solutions use ^: either. Just wondering whether ^: can help
> > here.
> >
> > On Thu, 16 Jan 2020, 12:36 'robert therriault' via Programming, <
> > programm...@jsoftware.com> wrote:
> >
> > > It is too late, considering the result is not the one that you requested!
> > >
> > > Anyway I would use a numerical approach something like the incorrect one
> > > that I just posted.
> > >
> > > Sheepishly - Cheers, bob
> > >
> > > > On Jan 15, 2020, at 23:03, 'robert therriault' via Programming <
> > > programm...@jsoftware.com> wrote:
> > > >
> > > > Hi Skip,
> > > >
> > > > A late snowy night silly approach
> > > >
> > > >]a=.20#1
> > > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> > > >   f1=. *@(3&|)@:i.@:#  NB. mod 3 non-zeros
> > > >   f1 a
> > > > 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
> > > >   f2=. -.@*@(2&|)@:i.@:#  NB. mod 2 zeros
> > > >   f2 a
> > > > 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
> > > >   (f1 *: f2) a  NB. Not-And fork
> > > > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> > > >   f=. f1 *: f2  NB. requested result
> > > >   f a
> > > > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> > > >
> > > > Cheers, bob
> > > >
> > > >
> > > >> On Jan 15, 2020, at 22:29, Skip Cave  wrote:
> > > >>
> > > >> ]a=.20#1
> > > >
> > > > --
> > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-16 Thread Raul Miller
Bits are a domain where identity values tend to be easy to find.

And, of course, the approach Roger Hui mentioned works great for this example:

Operation:  ~:
Identity value: 0
Mask: 0=3|i.@#

   a=:20#1
   (~: 0=3|i.@#) a
0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1

FYI,

-- 
Raul

On Thu, Jan 16, 2020 at 1:30 AM Skip Cave  wrote:
>
> Suppose I want to invert every 3rd binary bit, then every second bit where
> f is -. (selective not):
>
> ]a=.20#1
>
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>
> ]b=.3 f a
>
> 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
>
> ]c .2 f b
>
> 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1
>
>
> How to define f?
>
>
> Skip
>
>
>
>
>
> On Wed, Jan 15, 2020 at 8:30 PM Skip Cave  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
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-16 Thread R.E. Boss
   f=:  4 :',(-.@{. 0}])&.|: (-x)[\y'

   3 f a
0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 0
   2 f 3 f a
1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0


R.E. Boss


> -Oorspronkelijk bericht-
> Van: Programming 
> Namens Skip Cave
> Verzonden: donderdag 16 januari 2020 07:30
> Aan: programm...@jsoftware.com
> Onderwerp: Re: [Jprogramming] Selective verb application
> 
> Suppose I want to invert every 3rd binary bit, then every second bit where f
> is -. (selective not):
> 
> ]a=.20#1
> 
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 
> ]b=.3 f a
> 
> 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
> 
> ]c .2 f b
> 
> 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1
> 
> 
> How to define f?
> 
> 
> Skip
> 
> 
> 
> 
> 
> On Wed, Jan 15, 2020 at 8:30 PM Skip Cave 
> 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
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-16 Thread Skip Cave
I'm thinking of something along the lines of # (copy)

1 1 1 0 1 0 0 1 0 1 # i.10

0 1 2 4 7 9


Only "apply" uses a boolean left argument to define which elements on the
right are affected by the verb:


1 1 1 0 1 0 0 1 0 1 (apply -.) 1 1 1 1 1 1 1 1 1 1

0 0 0 1 0 1 1 0 1 0

1 1 1 0 1 0 0 1 0 1 (apply 2&+) 1 1 1 1 1 1 1 1 1 1

3 3 3 1 3 1 1 3 1 3

1 1 1 0 1 0 0 1 0 1 (apply 2&^~) i.10

0 1 4 3 16 5 6 49 8 81

Is this possible?

Skip Cave
Cave Consulting LLC


On Thu, Jan 16, 2020 at 2:08 AM Arnab Chakraborty  wrote:

> My first idea was to use ^: . But I am unable to get a solution. None of
> the posted solutions use ^: either. Just wondering whether ^: can help
> here.
>
> On Thu, 16 Jan 2020, 12:36 'robert therriault' via Programming, <
> programm...@jsoftware.com> wrote:
>
> > It is too late, considering the result is not the one that you requested!
> >
> > Anyway I would use a numerical approach something like the incorrect one
> > that I just posted.
> >
> > Sheepishly - Cheers, bob
> >
> > > On Jan 15, 2020, at 23:03, 'robert therriault' via Programming <
> > programm...@jsoftware.com> wrote:
> > >
> > > Hi Skip,
> > >
> > > A late snowy night silly approach
> > >
> > >]a=.20#1
> > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> > >   f1=. *@(3&|)@:i.@:#  NB. mod 3 non-zeros
> > >   f1 a
> > > 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
> > >   f2=. -.@*@(2&|)@:i.@:#  NB. mod 2 zeros
> > >   f2 a
> > > 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
> > >   (f1 *: f2) a  NB. Not-And fork
> > > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> > >   f=. f1 *: f2  NB. requested result
> > >   f a
> > > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> > >
> > > Cheers, bob
> > >
> > >
> > >> On Jan 15, 2020, at 22:29, Skip Cave  wrote:
> > >>
> > >> ]a=.20#1
> > >
> > > --
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-16 Thread Arnab Chakraborty
My first idea was to use ^: . But I am unable to get a solution. None of
the posted solutions use ^: either. Just wondering whether ^: can help here.

On Thu, 16 Jan 2020, 12:36 'robert therriault' via Programming, <
programm...@jsoftware.com> wrote:

> It is too late, considering the result is not the one that you requested!
>
> Anyway I would use a numerical approach something like the incorrect one
> that I just posted.
>
> Sheepishly - Cheers, bob
>
> > On Jan 15, 2020, at 23:03, 'robert therriault' via Programming <
> programm...@jsoftware.com> wrote:
> >
> > Hi Skip,
> >
> > A late snowy night silly approach
> >
> >]a=.20#1
> > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> >   f1=. *@(3&|)@:i.@:#  NB. mod 3 non-zeros
> >   f1 a
> > 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
> >   f2=. -.@*@(2&|)@:i.@:#  NB. mod 2 zeros
> >   f2 a
> > 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
> >   (f1 *: f2) a  NB. Not-And fork
> > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> >   f=. f1 *: f2  NB. requested result
> >   f a
> > 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> >
> > Cheers, bob
> >
> >
> >> On Jan 15, 2020, at 22:29, Skip Cave  wrote:
> >>
> >> ]a=.20#1
> >
> > --
> > For information about J forums see http://www.jsoftware.com/forums.htm
>
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-15 Thread 'robert therriault' via Programming
It is too late, considering the result is not the one that you requested!

Anyway I would use a numerical approach something like the incorrect one that I 
just posted.

Sheepishly - Cheers, bob

> On Jan 15, 2020, at 23:03, 'robert therriault' via Programming 
>  wrote:
> 
> Hi Skip,
> 
> A late snowy night silly approach
> 
>]a=.20#1
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>   f1=. *@(3&|)@:i.@:#  NB. mod 3 non-zeros
>   f1 a
> 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
>   f2=. -.@*@(2&|)@:i.@:#  NB. mod 2 zeros
>   f2 a
> 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
>   (f1 *: f2) a  NB. Not-And fork
> 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
>   f=. f1 *: f2  NB. requested result
>   f a
> 1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
> 
> Cheers, bob
> 
> 
>> On Jan 15, 2020, at 22:29, Skip Cave  wrote:
>> 
>> ]a=.20#1
> 
> --
> For information about J forums see http://www.jsoftware.com/forums.htm

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


Re: [Jprogramming] Selective verb application

2020-01-15 Thread 'robert therriault' via Programming
Hi Skip,

A late snowy night silly approach

]a=.20#1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
   f1=. *@(3&|)@:i.@:#  NB. mod 3 non-zeros
   f1 a
0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1
   f2=. -.@*@(2&|)@:i.@:#  NB. mod 2 zeros
   f2 a
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
   (f1 *: f2) a  NB. Not-And fork
1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1
   f=. f1 *: f2  NB. requested result
   f a
1 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 1 1

Cheers, bob


> On Jan 15, 2020, at 22:29, Skip Cave  wrote:
> 
> ]a=.20#1

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


Re: [Jprogramming] Selective verb application

2020-01-15 Thread Skip Cave
Suppose I want to invert every 3rd binary bit, then every second bit where
f is -. (selective not):

]a=.20#1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

]b=.3 f a

0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1

]c .2 f b

1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1


How to define f?


Skip





On Wed, Jan 15, 2020 at 8:30 PM Skip Cave  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


Re: [Jprogramming] Selective verb application

2020-01-15 Thread Julian Fondren
(flashing I-am-bad-at-J disclaimer)

Consider:

   ]a=.i.20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
   _3[\ a
 0  1  2
 3  4  5
 6  7  8
 9 10 11
12 13 14
15 16 17
18 19  0

every third element's right there in the first column.

thus:

   th =: 1 : ',(u@:{."1 ,. }."1) (-x)[\y'

which reshapes the list, applies the verb to the first column, then
stitches the result of that to the other columns, then returns a list.

   3 (_"_) th a
_ 1 2 _ 4 5 _ 7 8 _ 10 11 _ 13 14 _ 16 17 _ 19 0
   4 (_"_) th a
_ 1 2 3 _ 5 6 7 _ 9 10 11 _ 13 14 15 _ 17 18 19
   5 (_"_) th a
_ 1 2 3 4 _ 6 7 8 9 _ 11 12 13 14 _ 16 17 18 19

The resulting list can be padded with zeroes, but since the passed verb
will never apply to those, you can just strip them back off:

   th =: 1 : '(#y) $ ,(u@:{."1 ,. }."1) (-x)[\y'
   19 (_"_) th a
_ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 _
   NB. ^^^not still padded with 18 zeroes

On Wed, 2020-01-15 at 20:30 -0600, Skip Cave 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

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


Re: [Jprogramming] Selective verb application

2020-01-15 Thread Jimmy Gauvin
This works too :

   ,1 >:`+`+\i.20
1 1 2 4 4 5 7 7 8 10 10 11 13 13 14 16 16 17 19 19





On Wed, Jan 15, 2020 at 9:37 PM Roger Hui  wrote:

> Depends on the verb.  In the case >:,
>
>a=: i. 20
>n=: 3
>a + 0=n|i.#a
> 1 1 2 4 4 5 7 7 8 10 10 11 13 13 14 16 16 17 19 19
>
> Basically apply the verb or the identity function, depending on 0=n|i.#a .
>
>
>
> On Wed, Jan 15, 2020 at 6:30 PM Skip Cave  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
> >
> --
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Selective verb application

2020-01-15 Thread Roger Hui
Depends on the verb.  In the case >:,

   a=: i. 20
   n=: 3
   a + 0=n|i.#a
1 1 2 4 4 5 7 7 8 10 10 11 13 13 14 16 16 17 19 19

Basically apply the verb or the identity function, depending on 0=n|i.#a .



On Wed, Jan 15, 2020 at 6:30 PM Skip Cave  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
>
--
For information about J forums see http://www.jsoftware.com/forums.htm