Wait, I didn't deal properly with the second case because you had a different kind of 2 there. And your original example in your first post had still another different kind of 2. So I'd have to build a "2 normalizer" or something before this could work properly. It's perfectly doable, but I'm starting to wonder what problem you are really trying to solve.
((+:&.". ::+:)&.>@[`[@.] (2 -.@-:&": >))/\~&2 (<'a') ,~ ;/ 1 2 3 2 2 4 2 ┌─┬─┬─┬─┬─┬─┬─┐ │2│2│6│4│2│8│2│ └─┴─┴─┴─┴─┴─┴─┘ ((+:&.". ::+:)&.>@[`[@.] (2 -.@-:&": >))/\~&2 cut '1 2 3 2 2 4 2 a 1' ┌─┬─┬─┬─┬─┬─┬─┬─┐ │2│2│6│4│2│8│2│a│ └─┴─┴─┴─┴─┴─┴─┴─┘ ((+:&.". ::+:)&.>@[`[@.] (2 -.@-:&": >))/\~&2 ;/ 1 2 3 2 2 4 2 1 ┌─┬─┬─┬─┬─┬─┬─┐ │2│2│6│4│2│8│2│ └─┴─┴─┴─┴─┴─┴─┘ (I've used the same expression each time, just with different data, to demonstrate that it works.) But for the more general case you have proposed, where it's "n cells previous", I don't think I'd bother with the pattern I've used here, which I'd describe as: (dyad test)/\~2 Instead, I think I'd use (dyad n |.!.0 test) That's might be more efficient, also, and should behave better on empties. Thanks, -- Raul On Sun, May 18, 2014 at 12:56 PM, Raul Miller <[email protected]> wrote: > Here's an expression which handles both of the arguments you've given > here, and which roughly matches your original spec (though I've not added > the @(*@#) to make it work on empties): > > ((+:&.". ::+:)&.>@[`[@.] (~:&(0{cut'2')))/\~&2 cut '1 2 3 2 2 4 2 > a 1' > ┌─┬─┬─┬─┬─┬─┬─┬─┐ > │2│2│6│4│2│8│2│a│ > └─┴─┴─┴─┴─┴─┴─┴─┘ > ((+:&.". ::+:)&.>@[`[@.] (~:&(0{cut'2')))/\~&2 (<'a') ,~ ;/ 1 2 3 > 2 2 4 2 > ┌─┬─┬─┬─┬─┬─┬─┐ > │1│2│3│2│2│4│2│ > └─┴─┴─┴─┴─┴─┴─┘ > > > But you might want to replace +:&.". with a more constrained ":@+:@(_&".) > if you have any doubts about the structure of your input. (Like if it came > from a third party.) > > Thanks, > > -- > Raul > > > > On Sun, May 18, 2014 at 9:56 AM, 'Pascal Jasmin' via Programming < > [email protected]> wrote: > >> That is a cool way of getting doubles: >> >> ([: >: (<2) = 1 |. ]) ;/ 1 2 3 2 2 4 2 1 >> 2 1 2 2 1 2 1 1 >> >> I thank you for the creative approach, while still following all the >> directions. I learned something from all of the creative approaches >> provided. I was most interested in a good way to modify boxed data cells >> based on the content of other cells. I understand how people are helpfully >> trying to solve the problem they want to solve instead of magically reading >> my intent. When presenting the problem I prefer that there be a final >> unboxed presentation for display purposes, and I also prefer the simplest >> possible data argument, but it makes deciphering my intent more difficult. >> >> Here is a solution/problem statement that makes the boxed input >> requirement more than just an inconvenience. Perhaps if I put white space >> between the verb and data, its clear that the solution being sought should >> only modify the left of the white space: >> >> ((1|.(<2)=]each) +:@]^:[each ]) (<'a') ,~ ;/ 1 2 3 2 2 4 2 >> ┌─┬─┬─┬─┬─┬─┬─┬─┐ >> │2│2│6│4│2│8│2│a│ >> └─┴─┴─┴─┴─┴─┴─┴─┘ >> >> Though that example invites solutions that remove the tail then add it >> back later :P. So, perhaps I should provide 2 sample inputs: >> >> ((1|.(<2)=]each) +:@]^:[each ]) cut '1 2 3 2 2 4 2 a 1' >> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┐ >> │1│2│3│2│2│4│2│a│1│ >> └─┴─┴─┴─┴─┴─┴─┴─┴─┘ >> >> >> ________________________________ >> >> >> From: Joe Bogner <[email protected]> >> To: [email protected] >> Sent: Sunday, May 18, 2014 8:04:08 AM >> Subject: Re: [Jprogramming] ^: and boxes >> >> >> I would probably do this. Boxing is based on original requirement of right >> side being boxed >> >> (> * [: >: (<2) = 1 |. ]) ;/ 1 2 3 2 2 4 2 1 >> 2 2 6 4 2 8 2 1 >> >> Works on the negative test too >> >> (> * [: >: (<2) = 1 |. ]) ;/ _1 2 _3 2 2 _4 2 _1 >> _2 2 _6 4 2 _8 2 _1 >> >> It doesn't use ^: , which was in the subject line and may not be valid if >> ^: is required >> >> >> On Sat, May 17, 2014 at 11:28 AM, greg heil <[email protected]> wrote: >> >> > Linda >> > >> > >Wow that is super understandable and compact! Of course its domain is >> > limited, Eg it does not like negative numbers: >> > >> > d=: 1 2 3 2 2 4 2 1 >> > dn=: _1 2 _3 2 2 _4 2 _1 >> > dn=: (]* _1&^ @ (2~:])) d >> > >> > fLA=: ] >. +: * 1 |. 2 = ] >> > fLA dn >> > _1 2 _3 4 2 _4 2 0 >> > >> > >It did take me a _long_ time to penetrate Aai`s sophistry! Finally the >> > key was that /. was really oblique, not key! ...but it does survive this >> > negative number test: >> > >> > fA=: [: }. 2&*//.@(2&=,:]) >> > fA dn >> > _2 2 _6 4 2 _8 2 _1 >> > >> > >Anyway i think i am awake this am, thanks! i could be fooled though, >> only >> > dreaming i was awake;) >> > >> > greg >> > ~krsnadas.org >> > >> > -- >> > >> > from: Linda Alvord <[email protected]> >> > to: [email protected] >> > date: 16 May 2014 21:51 >> > subject: Re: [Jprogramming] ^: and boxes >> > >> > Maybe you'll like this. >> > >> > >> > f=: 13 :'y >.(1 |. 2 = y)*+:y' >> > f 1 2 3 2 2 4 2 >> > 2 2 6 4 2 8 2 >> > >> > f >> > ] >. +: * 1 |. 2 = ] >> > >> > Linda >> > ---------------------------------------------------------------------- >> > 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
