http://www.jsoftware.com/jwiki/Essays/Inverse_Permutation presents different ways of computing the inverse permutation.
----- Original Message ----- From: Zsbán Ambrus <[EMAIL PROTECTED]> Date: Thursday, November 6, 2008 1:38 Subject: Re: [Jprogramming] cut on length To: Programming forum <[email protected]> > On Thu, Nov 6, 2008 at 02:04, Roger Hui <[EMAIL PROTECTED]> wrote: > > ts 'p i. i.#p' > > 0.00602786 1.57363e6 > > > > Compared to: > >> ts '/:p' > >> 0.00611782 1.04922e6 > >> ts '(i.#p) p}p' > >> 0.0112338 1.57389e6 > > My story is actually this. Back in 2005, someone asked an > interestingpuzzle in "http://www.perlmonks.com/?node_id=487200", > which asked to > generate a certain spiral. In the first solution I wrote > ("http://www.perlmonks.com/?node_id=487238"), I used p i. i.#p to > generate the inverse of a permutation. The original > solution was > basically this (except that it had y. instead of y): > > spiral =: 3 : 0 > >: (,~ y) $ (i. *: y) i.~ /: ,/ (-@>.&| , - > @{:@*.@(1j_1&*)@j.)"0/~ (i. y) - -:<: y > ) > spiral 5 > 1 2 3 4 5 > 16 17 18 19 6 > 15 24 25 20 7 > 14 23 22 21 8 > 13 12 11 10 9 > > Then, when I translated this to perl > ("http://www.perlmonks.com/?node_id=487246"), I realized this, and > instead used the equivalent of ((i.#p) p} p). > > Much later, in 2007, when this topic came up in the jprogramming list, > I rewrote my J solution to use ((i.#p) p} p) instead: > "http://www.jsoftware.com/pipermail/programming/2007- > December/009009.html". I also copied this back to the > perlmonks thread. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
