I'm trying to take a set of numbers and find a list of all the possible (positive) results of adding or subtracting those numbers. So for 1 4 9 the result would be 4 6 12 14.

I spent some time trying to figure out how to come up with a verb that could be inserted between each atom of the list that would get the positive and negative of the argument to its right, add that to each item of the list to its left, get the nub of that list, and then continue on, but that didn't work.

Then I happened to try (+,-)/ to see what it would do, and low and behold it seemed to generate most of the possible values (?) For example:

   (+,-)/ 1 2 3
6 0 _4 2

I have no idea what is going on here. Can anyone explain? In short sentences of small words ;-)

The train I ended up with is shown below. It seems to work, but is it right?

   /:~ ~. | (+,-)/ 3 6 11 12
2 4 8 10 14 20 26 32

Also (sorry to still be tossing out newbie questions) if this is right, how do I package it up so I can use it:

   v=: /:~ ~. | (+,-)/
   v 1 2 3 4
|length error: v

Thanks -- still having fun!
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to