A couple of years ago I concocted a way to solve these kind of problems,
Wide cut <http://www.jsoftware.com/jwiki/RE%20Boss/J-blog/WideCut> 

Applying this gives 

 

   (+/\* 2 4 8 e.~4(2&#.)\0,~ 0 0,]) 0 1 0 0 0 0 0 0 1 0 0

0 1 1 1 0 0 0 0 2 2 2

 

 

R.E. Boss

 

(Add your info to  <http://www.jsoftware.com/jwiki/Community/Demographics>
http://www.jsoftware.com/jwiki/Community/Demographics )

 

 

> -----Original Message-----

> From: [email protected] [mailto:programming-

> [email protected]] On Behalf Of R.E. Boss

> Sent: woensdag 28 januari 2015 8:09

> To: [email protected]

> Subject: Re: [Jprogramming] scan replace

> 

> My 2 cents

> 

>    (+/\ * [:+/ (-i.3) |."(0 1)]) 0 1 0 0 0 0 0 0 1 0 0

> 0 1 1 1 0 0 0 0 2 2 2

> 

> 

> R.E. Boss

> 

> (Add your info to

>  <http://www.jsoftware.com/jwiki/Community/Demographics>
http://www.jsoftware.com/jwiki/Community/Demographics )

> 

> 

> > -----Original Message-----

> > From:  <mailto:[email protected]>
[email protected]

> [mailto:programming-

> >  <mailto:[email protected]> [email protected]] On
Behalf Of Raul Miller

> > Sent: woensdag 28 januari 2015 5:46

> > To: Programming forum

> > Subject: Re: [Jprogramming] scan replace

> >

> > I guess this is how I'd write that:

> >

> >    f=: (3##\@])`(,@])`[} 0 1 2 +/~I.

> >

> > Is that easy enough to read, or should I spell out how it works?

> >

> > Thanks,

> >

> > --

> > Raul

> >

> > On Tue, Jan 27, 2015 at 10:42 PM, Joe Bogner <
<mailto:[email protected]> [email protected]>

> > wrote:

> > > I'm looking for some help to write a verb to find 1s and replace it

> > > and the next two numbers with an incrementing sequence.

> > >

> > >

> > > 0 1 1 1 0 0 0 0 2 2 2 -: f 0 1 0 0 0 0 0 0 1 0 0

> > >

> > > I tried variations of scan[1] and the recent thread on Forward Fill[2]

> > > seems to apply

> > >

> > > I don't understand either well enough to apply it.

> > >

> > > I should be able to do something like this:

> > >

> > > 1. Reverse |. 0 1 0 0 0 0 0 0 1 0 0

> > >

> > > 0 0 1 0 0 0 0 0 0 1 0

> > >

> > > 2. Scan

> > >

> > > 0

> > > 0 0

> > > 0 0 1 -> replace last 3 with 1+ the largest number found,  1 1 1

> > > 1 1 1 0

> > > 1 1 1 0 0

> > > 1 1 1 0 0 0

> > > 1 1 1 0 0 0 0

> > > 1 1 1 0 0 0 0 0

> > > 1 1 1 0 0 0 0 0 0

> > > 1 1 1 0 0 0 0 0 0 1 -> replace last 3 with 1 + the largest number
found

> 2 2 2

> > > 1 1 1 0 0 0 0 2 2 2

> > > 1 1 1 0 0 0 0 2 2 2 0

> > >

> > > Assuming this is a reasonable way to tackle it, what would the correct

> > > scan be and would you use ^: to match the last value of the scan and

> > > replace the prior three values with the >./ of the list?

> > >

> > > 3. Reverse |. 1 1 1 0 0 0 0 2 2 2 0

> > >

> > > 0 2 2 2 0 0 0 0 1 1 1

> > >

> > >

> > > This isn't exactly what I'm looking for since I scanned in reverse. I

> > > would be happy with this or even happier with the desired 0 1 1 1 0 0

> > > 0 0 2 2 2

> > >

> > > Thanks

> > >

> > >

> > > [1] -

> >  <http://www.jsoftware.com/jwiki/OlegKobchenko/Ways%20to%20Scan>
http://www.jsoftware.com/jwiki/OlegKobchenko/Ways%20to%20Scan

> > > [2] -  <http://jsoftware.com/pipermail/programming/2015->
http://jsoftware.com/pipermail/programming/2015-

> > January/040706.html

> > > ----------------------------------------------------------------------

> > > For information about J forums see

> >  <http://www.jsoftware.com/forums.htm>
http://www.jsoftware.com/forums.htm

> > ----------------------------------------------------------------------

> > For information about J forums see

>  <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm

> ----------------------------------------------------------------------

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

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

Reply via email to