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