You can clean this up a bit by using a verb to turn each 1 into a 1 1 1
in a boolean sequence (there are a few ways to do this, although I
haven't thought of anything particularly elegant yet). This makes it so
that entries on the left overwrite those on the right; it's not easy to
make it go the other way.

   ((2+./\0&,)^:2 * +/\) 0 1 0 1 1 1 0 1 1 0 0
0 1 1 2 3 4 4 5 6 6 6

Marshall

On Wed, Jan 28, 2015 at 04:10:56AM +0000, 'Pascal Jasmin' via Programming wrote:
> this matches
> 
>   ,`([ , 0 1})@.(0<[)/@:(* +/\) 0 1 0 0 0 0 0 0 1 0 0 
> 0 1 1 1 0 0 0 0 2 2 2 
> 
> 
> not sure if this is what you want though:
> 
>    ,`([ , 0 1})@.(0<[)/@:(* +/\) 0 1 0 0 0 0 0 1 1 0 0 
> 0 1 1 1 0 0 0 2 2 2 3 
> 
> 
>  
>    ,`([ , 0 1})@.(0<[)/@:(* +/\) 0 1 0 1 1 1 0 1 1 0 0 
> 0 1 1 1 2 2 3 4 5 5 6 
> 
> 
> 
> 
> ----- Original Message -----
> From: Joe Bogner <[email protected]>
> To: [email protected]
> Cc: 
> Sent: Tuesday, January 27, 2015 10:42 PM
> Subject: [Jprogramming] scan replace
> 
> 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
> [2] - http://jsoftware.com/pipermail/programming/2015-January/040706.html
> ----------------------------------------------------------------------
> 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

Reply via email to