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

Reply via email to