[Jprogramming] Forward fill w/o looping

Roger Hui rogerhui.canada at gmail.com
Mon Jan 5 20:08:12 UTC 2015


   fef=: a:&~: (+/\@[ { {.@] , # ) ]
   fef t
┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐
││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│
└┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘



On Mon, Jan 5, 2015 at 10:46 AM, 'Pascal Jasmin' via Programming <
programming at jsoftware.com> wrote:

> a verbed variation of Roger's
>
> (] (({.@:[ , #~) {~  +/\@:] ) [: * #&>)
> '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';''
>
>
>
>
> ----- Original Message -----
> From: Roger Hui <rogerhui.canada at gmail.com>
> To: Programming forum <programming at jsoftware.com>
> Cc:
> Sent: Monday, January 5, 2015 11:59 AM
> Subject: Re: [Jprogramming] Forward fill w/o looping
>
>    t=: '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';''
>
>    fillEmptyFwd t
> ┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐
> ││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│
> └┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘
>    (({.t),b#t) {~ +/\b=: *#&>t
> ┌┬──┬──┬──┬──┬──┬───┬───┬───┬───┬───┬───┬──┬──┐
> ││Hi│Hi│Hi│Ho│Ho│hee│hee│hee│haw│haw│haw│Yo│Yo│
> └┴──┴──┴──┴──┴──┴───┴───┴───┴───┴───┴───┴──┴──┘
>
>
>
> On Mon, Jan 5, 2015 at 8:06 AM, Devon McCormick <devonmcc at gmail.com>
> wrote:
>
> > I just threw together a short J solution that does what I want but it
> uses
> > a loop and a conditional.  I'm thinking there's got to be some kind of
> > loopless prefix sort of solution but am at a loss to come up with it.
> >
> > My code looks like this:
> >
> > fillEmptyFwd=: 3 : 0
> > for_ix. i.<:#y do.
> >     if. 0=#>y{~>:ix do. y=. (ix{y) (>:ix)}y end.
> > end.
> > y
> > )
> >
> > An example usage would be this:
> >
> >    fillEmptyFwd '';'Hi';'';'';'Ho';'';'hee';'';'';'haw';'';'';'Yo';''
> > ++--+--+--+--+--+---+---+---+---+---+---+--+--+
> > ||Hi|Hi|Hi|Ho|Ho|hee|hee|hee|haw|haw|haw|Yo|Yo|
> > ++--+--+--+--+--+---+---+---+---+---+---+--+--+
> >
> > Any ideas on something less loopy/conditional?
>


More information about the Programming mailing list