Oh, wait, wasn't paying enough attention.
Perhaps this:
f=: 2&{@]`(1&{::@])`(0&{::@])}"1~@(([;"1((<"0@],.{~)&>/)@(];I.@:~:)) +//.~&.>)
(beware email line wrap - also, google's "Message text Garbled?"
option from the drop-down menu to the right of the reply button is
your friend, if you are using gmail, since that undoes some of the
garbling that gmail induces. But if you are getting line wrap in your
email system you'll need to copy and paste into a text editor or J
edit session and manually undo the line wrapping there.)
And, to see something of how this works (since I glazed over on my
first read, I expect I should make at least some efforts on behalf of
those who do not themselves do so when reading this message):
First, we need our sample data:
N=:10&#.inv&.>12 22 24 41 15 53 34 44 44 42 23 33
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│
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
Then, we verify my expression:
2&{@]`(1&{::@])`(0&{::@])}"1~@(([;"1((<"0@],.{~)&>/)@(];I.@:~:)) +//.~&.>)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 │
└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
Then we strip off the merge operation, to see what it's working with:
(([;"1((<"0@],.{~)&>/)@(];I.@:~:)) +//.~&.>)N
┌─────────────────────────────────────────────────┬──┬─┐
│┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│1 │4│
││1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3││ │ │
│└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘│ │ │
├─────────────────────────────────────────────────┼──┼─┤
│┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│7 │8│
││1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3││ │ │
│└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘│ │ │
├─────────────────────────────────────────────────┼──┼─┤
│┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│8 │8│
││1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3││ │ │
│└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘│ │ │
├─────────────────────────────────────────────────┼──┼─┤
│┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│11│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││ │ │
│└───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘│ │ │
└─────────────────────────────────────────────────┴──┴─┘
And we can back that out just a bit more to see an earlier intermediate result:
((((<"0@],.{~)&>/)@(];I.@:~:)) +//.~&.>)N
┌──┬─┐
│1 │4│
├──┼─┤
│7 │8│
├──┼─┤
│8 │8│
├──┼─┤
│11│6│
└──┴─┘
And that, in turn, was built from:
(((];I.@:~:)) +//.~&.>)N
┌─────────────────────────────────────────┬────────┐
│┌───┬─┬───┬───┬───┬───┬───┬─┬─┬───┬───┬─┐│1 7 8 11│
││1 2│4│2 4│4 1│1 5│5 3│3 4│8│8│4 2│2 3│6││ │
│└───┴─┴───┴───┴───┴───┴───┴─┴─┴───┴───┴─┘│ │
└─────────────────────────────────────────┴────────┘
... anyways, perhaps with a few more experiments you can see and/or
explain how these pieces fit together.
And, once again, my apologies for my earlier post - I should be a bit
more careful when replying while I am still waking up.
Thanks,
--
Raul
On Mon, Nov 7, 2016 at 7:48 AM, Raul Miller <[email protected]> wrote:
> How about:
> f=: +//.~&.>
>
> Does that work for you?
>
> Thanks,
>
> --
> Raul
>
>
> On Mon, Nov 7, 2016 at 2:23 AM, Skip Cave <[email protected]> wrote:
>> Problem update:
>>
>> Instead of starting with multiple duplicated rows, I want to start with one
>> row containig 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│
>>
>> └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
>>
>> 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 boxed duplicate
>> pair with a box containing the sum of the two integers. However, I want to
>> create a new row for each dup pair we find, and append that new row on the
>> bottom of the specific dup pair with the sum of the two numbers. 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 │
>>
>> └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
>>
>> The row append process stops if all duplicates have been found.
>>
>> 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