This is perfect and even simpler and more elegant than I expected. Thank you On Jan 27, 2015 11:11 PM, "'Pascal Jasmin' via Programming" < [email protected]> 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
