f=: (] dyax ywx)"_ 0 ind
ind=: [: I. 2 =/\ ] NB. indices of 1st number in pairs
dyax=: +:@{`[`]} NB. double y at x index
ywx=: <^:3@] { [ NB. y without x index
Take a look at the dictionary page for } (ammend) with gerunds (` expressions).
In addition, a triply-boxed left argument to { simply removes the item at that
index in y.
As to the missing left argument to the "_ 0 verb, a hook (f g) y evaluates to y
f g y.
Hope this helps,
Louis
> On 08 Nov 2016, at 06:17, Skip Cave <[email protected]> wrote:
>
> Nice! Xiao-Yong's verb does exactly what I need.
>
> f=:(] +:@{`[`]} <@<@<@]{[)"_ 0 [:I.2=/\]
>
> t =. 1 2 2 4 1 5 3 4 4 4 2 3 3
>
> f t
>
> 1 4 4 1 5 3 4 4 4 2 3 3
>
> 1 2 2 4 1 5 3 8 4 2 3 3
>
> 1 2 2 4 1 5 3 4 8 2 3 3
>
> 1 2 2 4 1 5 3 4 4 4 2 6
>
>
> I can understand [:I.2=/\]. Using I. is the perfect way to find the
> indices of the dups. However, the rest of that big infinite-rank tacit
> expression to the left must generate each of the reduced items. I'm totally
> lost trying to figure that out. Why the zero? Why three <@? I thought [
> represented a left argument, but there isn't a left argument. Any help is
> appreciated.
>
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Mon, Nov 7, 2016 at 10:25 PM, Xiao-Yong Jin <[email protected]>
> wrote:
>
>> So you probably just need this:
>> f=:(] +:@{`[`]} <@<@<@]{[)"_ 0 [:I.2=/\]
>> or really the adverb
>> a=:1 :'u@(] +:@{`[`]} <@<@<@]{[)"_ 0 [:I.2=/\]'
>>
>> You may find different solutions if you abstract your problem differently.
>>
>>> On Nov 7, 2016, at 9:30 PM, Skip Cave <[email protected]> wrote:
>>>
>>> Very interesting. Quite a difference in space and time usage, not to
>>> mention length of the tacit code.
>>>
>>> For my application, a rank 0 or 1 in the summed result isn't all that
>>> critical. As long as the contents of each box can be used in further
>>> arithmetic and Boolean operations (e.g. it's not text), then I'm ok.
>>>
>>>
>>> It looks like nouns with ranks 0 or 1 don't affect the outcome of simple
>>> arithmetic operations:
>>>
>>>
>>> ($4);($,4);(4=,4);(1+4);(1+,4);((1+4)=1+,4);($1+4);($1+,4)
>>>
>>> ┌┬─┬─┬─┬─┬─┬┬─┐
>>>
>>> ││1│1│5│5│1││1│
>>>
>>> └┴─┴─┴─┴─┴─┴┴─┘
>>>
>>> The only time the difference becomes an issue:
>>>
>>> ($4)=($,4)
>>>
>>> |length error
>>>
>>> | ($4) =($,4)
>>> But I don't care about this.
>>>
>>> Actually, Mike Day spotted what I was really trying to attempt.
>>> The original starting vector is:
>>>
>>> n =: 1 2 2 4 1 5 3 4 4 4 2 3 3
>>>
>>> Then I box at each possible pair of integers using an infix
>> sliding-window
>>> on each pair of integers. This sliding box scheme was just to identify
>> all
>>> the duped pairs in the original vector.
>>>
>>> ]N =: 2<\pp
>>>
>>> ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
>>>
>>> │1 2│2 2│2 4│4 1│1 5│5 3│3 4│4 4│4 4│4 2│2 3│3 3│
>>>
>>> └───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┘
>>>
>>>
>>> What I ultimately wanted is a verb that will replace the duped pairs in
>> the
>>> *original* un-boxed vector, one at a time:
>>>
>>> n =: 1 2 2 4 1 5 3 4 4 4 2 3 3
>>>
>>> f n
>>>
>>> 1 4 4 1 5 3 4 4 4 2 3 3
>>>
>>> 1 2 2 4 1 5 3 8 4 2 3 3
>>>
>>> 1 2 2 4 1 5 3 4 8 2 3 3
>>>
>>> 1 2 2 4 1 5 3 4 4 4 2 6
>>>
>>> Of course, the final row lengths will be one shorter that the original
>> row
>>> length.
>>>
>>> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm