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

Reply via email to