Prefixes of suffixes.  Very neat.

   <\\. 'abcde'
┌─┬──┬───┬────┬─────┐
│a│ab│abc│abcd│abcde│
├─┼──┼───┼────┼─────┤
│b│bc│bcd│bcde│     │
├─┼──┼───┼────┼─────┤
│c│cd│cde│    │     │
├─┼──┼───┼────┼─────┤
│d│de│   │    │     │
├─┼──┼───┼────┼─────┤
│e│  │   │    │     │
└─┴──┴───┴────┴─────┘

Suffixes of prefixes will also work.

   <\.\ 'abcde'
┌─────┬────┬───┬──┬─┐
│a    │    │   │  │ │
├─────┼────┼───┼──┼─┤
│ab   │b   │   │  │ │
├─────┼────┼───┼──┼─┤
│abc  │bc  │c  │  │ │
├─────┼────┼───┼──┼─┤
│abcd │bcd │cd │d │ │
├─────┼────┼───┼──┼─┤
│abcde│bcde│cde│de│e│
└─────┴────┴───┴──┴─┘



----- Original Message -----
From: Marshall Lochbaum <[email protected]>
Date: Friday, September 16, 2011 10:44
Subject: Re: [Jprogramming] Consecutive Numbers in List
To: Programming forum <[email protected]>

>    ; <@:(+/\)\. p:i.4
> 2 5 10 17 3 8 15 5 12 7
> 
> applies +/ on prefixes of suffixes.
> 
> Marshall
> 
> On Fri, Sep 16, 2011 at 12:59 PM, Roger Hui <[email protected]> 
> wrote:
> > Multiple applications of the infix x +/\ y does the trick.
> >
> >   f=: >:@i.@# +/\&.>  <
> >   f 2 3 5 7
> > ┌───────┬──────┬─────┬──┐
> > │2 3 5 7│5 8 12│10 15│17│
> > └───────┴──────┴─────┴──┘
> >   g=: ;@f
> >   g 2 3 5 7
> > 2 3 5 7 5 8 12 10 15 17
> >
> > The results of f are the 1-, 2-, 3-, and 4-infix sums.
> > Razing the whole thing gets the desired result.
> >
> >
> >
> > ----- Original Message -----
> > From: David Vaughan <[email protected]>
> > Date: Friday, September 16, 2011 9:49
> > Subject: [Jprogramming] Consecutive Numbers in List
> > To: Programming forum <[email protected]>
> >
> > > I'm trying to get a list of the sum of all possible consecutive
> > > numbers.
> > > E.g.
> > >
> > > for p:i.4, I want a list:
> > >
> > > 2 0 0 0
> > > 2 3 0 0
> > > 2 3 5 0
> > > 2 3 5 7
> > > 3 5 7 0
> > > 5 7 0 0
> > > 7 0 0 0
> > > 3 5 0 0
> > >
> > > I then do +/"1 to get the sum of each row. My problem is that
> > > I'm only getting consecutive numbers that start on p:0 or 
> end on
> > > the last value, so it misses out loads in between. In the
> > > example above I get all but the last row. This is what I 
> have so far:
> > >
> > >    list=:3 :'(+/"1@>{\p:i.y),+/"1@>{\.p:i.y'
> > >    list 10
> > > 2 5 10 17 28 41 58 77 100 129 129 127 124 119 112 101 88 71 
> 52 29
> > >
> > > Also I was wondering if there was a way to streamline something
> > > like that because I'm doing +/"1@>{\.p:i.y twice basically, but
> > > with \. changed to \

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to