On Fri, Sep 16, 2011 at 12:48 PM, David Vaughan
<[email protected]> wrote:
> I'm trying to get a list of the sum of all possible consecutive numbers.

Does the order of the result matter?

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

   (;@(# <@(i.@-   |."0 1   [ {. 1 #~ 1+])"0 i.@#) +/ .* ]) p:i.4
2 7 5 3 5 9 12 10 12 17
   ;@(# <@(-@i.@-   |."0 1   [ {. 1 #~ 1+])"0 i.@#)  p:i.4
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
1 1 0 0
0 1 1 0
0 0 1 1
1 1 1 0
0 1 1 1
1 1 1 1

(Note that I changed the order of things, slightly, between those two
sentences -- they are not exactly parallel, though obviously they are
structurally similar.  Can you see where I changed the order of the
items?)

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

Reply via email to