I liked Ambrus's reminder earlier that, when manipulating
permutations, sheer arithmetic with booleans should not be overlooked.


On Sun, May 1, 2011 at 9:40 PM, Roger Hui <[email protected]> wrote:
> I think you mean (i.#p) p}p .
>
>   p=: 8?8
>   1 p}p
> 1 1 1 1 1 1 1 1
>   (i.#p) p}p
> 2 3 4 6 5 1 7 0
>   /: p
> 2 3 4 6 5 1 7 0
>
> That is one of the APL circumlocutions, p[p]←⍳⍴p.
> The relative timings of /:p vs. (i.#p) p}p is left as
> an exercise for the reader. :-)
>
>
>
> ----- Original Message -----
> From: Zsbán Ambrus <[email protected]>
> Date: Sunday, May 1, 2011 13:29
> Subject: Re: [Jprogramming] A permutation of i.y
> To: Programming forum <[email protected]>
>
>> On Sun, May 1, 2011 at 10:10 PM, Ian Clark
>> <[email protected]> wrote:
>> > I was well aware of the properties of grade-up (⍋) -- after
>> all it
>> > returns a rearrangement to the ordered list, ie inverts the
>> > rearrangement -- but didn't use it because it did a sort, preferring
>> > to use iota (⍳) --c/f (i.).
>> >
>> > I note your point that we have much better sorts nowadays...
>> >
>> > ]   p=: 8?8
>> > 6 0 1 7 2 3 5 4
>> >   I=: i.8
>> >   p i. I      NB. invert p
>> > 1 2 4 5 7 6 0 3
>> >   /:p        NB. ditto
>> > 1 2 4 5 7 6 0 3
>>
>> Don't forget that there's a third solution, which could be
>> better than
>> either of the search and the sort:
>>
>>    l p} p
>> 1 2 4 5 7 6 0 3
>>
>> Ambrus
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to