,.t<@(({: - {.);._3) lst
+--------------------------+
|0 0 0 0 0 0 0 0 0 0 0 0   |
+--------------------------+
|5 4 _7 2 6 _2 4 _1 _4 _3 4|
+--------------------------+
|9 _3 _5 8 4 2 3 _5 _7 1   |
+--------------------------+
|2 _1 1 6 8 1 _1 _8 _3     |
+--------------------------+
|4 5 _1 10 7 _3 _4 _4      |
+--------------------------+
|10 3 3 9 3 _6 0           |
+--------------------------+
|8 7 2 5 0 _2              |
+--------------------------+
|12 6 _2 2 4               |
+--------------------------+
|11 2 _5 6                 |
+--------------------------+
|7 _1 _1                   |
+--------------------------+
|4 3                       |
+--------------------------+

where 
   t=. ,:/"(1)1,.}.i.# lst

For columns in tables you should do

   <"2 t=.(_,. ,:/)"(1)1,.2}.i.{:$ tbl=. i.5 7
+---+---+---+---+---+
|_ 1|_ 1|_ 1|_ 1|_ 1|
|_ 2|_ 3|_ 4|_ 5|_ 6|
+---+---+---+---+---+

      t<@(({:-{.)"1;._3) tbl
+---------+---------+---------+---------+---------+
|1 1 1 1 1|2 2 2 2 2|3 3 3 3 3|4 4 4 4 4|5 5 5 5 5|
|1 1 1 1 1|2 2 2 2 2|3 3 3 3 3|4 4 4 4 4|5 5 5 5 5|
|1 1 1 1 1|2 2 2 2 2|3 3 3 3 3|4 4 4 4 4|         |
|1 1 1 1 1|2 2 2 2 2|3 3 3 3 3|         |         |
|1 1 1 1 1|2 2 2 2 2|         |         |         |
|1 1 1 1 1|         |         |         |         |
+---------+---------+---------+---------+---------+


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens PackRat
> Verzonden: donderdag 30 december 2010 5:39
> Aan: Programming forum
> Onderwerp: [Jprogramming] Non-successive passive subtractions
> 
> I'm working with "passive subtraction":  tbl2=. 2 -~/ \"1 tbl
> 
> However, I need to create a series of such subtractions where 2 columns
> at a time are still used but where the distance between the columns
> subtracted can vary.  For simplicity, I'll just use a list (rather than
> table) of numbers to show what I'm after:
> 
>    lst=. 3 8 12 5 7 13 11 15 14 10 7 11
> 
> The first result would be the same as above, where the subtracted
> elements are 1 apart, that is, adjacent (I'm showing the subtractions
> rather than the results, but, of course, I really want the subtraction
> results) (#lst1 is 11):
> 
>    lst1=. 8-3 12-8 5-12 7-5 13-7 11-13 15-11 14-15 10-14 7-10 11-7
> 
> The next result would do the same passive subtraction, only on elements
> that are 2 apart (rather than adjacent) (#lst2 is 10):
> 
>    lst2=. 12-3 5-8 7-12 13-5 11-7 15-13 14-11 10-15 7-14 11-10
> 
> The third result would do the same passive subtraction, only on
> elements that are 3 apart (#lst3 is 9):
> 
>    lst3=. 5-3 7-8 13-12 11-5 15-7 14-13 10-11 7-15 11-14
> 
> And so on.  The tenth result's elements are 10 elements apart (#lst10
> is 2):
> 
>    lst10=. 7-3 11-8
> 
> And the eleventh result's elements are 11 elements apart (#lst11 is 1):
> 
>    lst11=. 11-3
> 
> It would seem logical that perhaps there's a single algorithm with a
> variable along the lines of  i.(#lst-1)  or else the distance apart of
> the subtracted elements could be the x argument of a verb (including an
> i.(#lst-1) type of argument), where lst is the y argument.  A table
> produced by an i.(#lst-1) type of variable or argument should be zero-
> filled.  (I don't need it for my particular application, but I presume
> that if the y argument were a table rather than a list, then the end
> result would be a table of tables.)
> 
> This whole thing has a very practical application to something I'm
> working on, and I would appreciate any help that anyone has to offer.
> Thanks in advance for your assistance!
> 
> Harvey
> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to