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 <[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 > [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
