Trying Louis' program: sumpears=: +/@]^:[&.>~ (*. 1 = +/\"1)@:(=/@>)
n ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ sumpears n ┌───┬─┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │1 2│4│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼─┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│4│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼─┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│4│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼─┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│4│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ └───┴─┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ So this verb replaces the first pair (2,2) with 4, but it replaces the SAME pair in every row. I want it to replace a DIFFERENT pair in each row. like this: sumpears n ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │1 2│ 4 │2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│ 8 │4 4│4 2│2 3│3 3│ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│ 8 │4 2│2 3│3 3│ ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│ 6 │ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ Also ideally I would like to start out with just one row of boxed pairs: n ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ The pair replacement process would add a new row for each duplicate pair, and stop when all the dup pairs have been replaced by sums. Skip Skip Cave Cave Consulting LLC On Mon, Nov 7, 2016 at 1:19 AM, Louis de Forcrand <[email protected]> wrote: > sumpears=: +/@]^:[&.>~ (*. 1 = +/\"1)@:(=/@>) > > Does this do what you want? > > Louis > > > > Sent from my iPhone > > On 07 Nov 2016, at 05:50, Skip Cave <[email protected]> wrote: > > > > NB. I have the following array n consisting of 5 identical rows of boxed > > pairs of integers: > > > > n > > > > ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ > > > > > > I want to design a verb f such that it will find boxes containing > duplicate > > pairs in n. f will sum the duplicate pairs, and replace the duplicate > with > > the sum of the two pairs. However, I want to do this only once for each > row, > > > > and find a new pair in the subsequent row to replace. See the result > below. > > > > f n > > > > ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ > > > > │1 2│ 4 │2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│ 8 │4 4│4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│ 8 │4 2│2 3│3 3│ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│ 6 │ > > > > ├───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┤ > > > > │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│ > > > > └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘ > > > > If all duplicates have been found, no change will be made in the row. > > > > Can this be done without control statements? > > > > > > Skip > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
