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
