lst=: 3 8 12 5 7 13 11 15 14 10 7 11
2 ({:-{.)\lst
5 4 _7 2 6 _2 4 _1 _4 _3 4
3 ({:-{.)\lst
9 _3 _5 8 4 2 3 _5 _7 1
4 ({:-{.)\lst
2 _1 1 6 8 1 _1 _8 _3
5 ({:-{.)\lst
4 5 _1 10 7 _3 _4 _4
----- Original Message -----
From: PackRat <[email protected]>
Date: Wednesday, December 29, 2010 20:40
Subject: [Jprogramming] Non-successive passive subtractions
To: Programming forum <[email protected]>
> 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!
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm