I haven't read your permutation verb in detail, but I noticed the x: . Extended integers are notoriously space hungry, so wonder if they're the cause of your disk swapping. You might try normal integers; since the task limits itself to !10 , I don't think extended precison is required.
The usual phrase for permutations is something along the lines of (A.&i.~ !) . But note that just as (1={.) is a stopping condition for swops, so is (0={.) . So the standard representation for permutations, which includes zero, is inappropriate for this task. Permutations which include zeros result in early returns, truncated swop lists, and reduced swop counts. To avoid that, we could rephrase the permutation function as ((A.>:)&i.~ !) . -Dan Please excuse typos; composed on a handheld device. On Nov 26, 2012, at 11:29 PM, David Ward Lambert <b49p23t...@stny.rr.com> wrote: > I'm glad I asked. > 1) I'd forgotten or never knew about ^:a: > 2) I struggled to get the solution for 9, and my solution page faulted > to death at 10. > > permutations > ((i.@:(-&! <:) + !@:<:)@:x: A. >:@:i.)^:(1&<) > > <@permutations"0 [ 1 3 > +-+-----+ > |1|2 1 3| > | |2 3 1| > | |3 1 2| > | |3 2 1| > +-+-----+ > > >>> Reference: http://rosettacode.org/wiki/Topswops >> Date: Mon, 26 Nov 2012 22:19:42 -0500 >> From: Dan Bron <j...@bron.us> >> To: "programm...@jsoftware.com" <programm...@jsoftware.com> >> Subject: Re: [Jprogramming] count iterations >> Message-ID: <53154fe6-9368-45b0-8120-ba3e3861e...@bron.us> >> Content-Type: text/plain; charset=us-ascii >> >> I added a solution to the task at RosettaCode. If we let J do the >> work for us, the solution is fairly simple. We use ^:a: ("swop" until >> you hit your fixed point, i.e. until 1={. ) and the count is the >> number of swops, i.e. the length of the result. >> >> The task calls for calculating the "topswop" all possible permutations >> of N integers (i.e. the maximal number of swops for any given >> permutation of rank N). The task only calls for N up to 10, so brute >> force (calculating all !N swops and taking the max) suffices. But >> for large N, brute force would explode, so another method would be >> required. >> >> Just looking at the series, I suspect a simple arithmetical >> (combinatorical) solution exists. It might even be ready-made in the >> OEIS. But I'll leave that to you smart guys. >> >> -Dan > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm