I'm learning a lot too. f=: 13 :'(|.({.y){.y),({.y)}.y' f ([: |. {. {. ]) , {. }. ] swops2=: f^:a: swops2 2 3 5 1 4 2 3 5 1 4 3 2 5 1 4 5 2 3 1 4 4 1 3 2 5 2 3 1 4 5 3 2 1 4 5 1 2 3 4 5
Tackling all the permutations look daunting. Linda -----Original Message----- From: programming-boun...@forums.jsoftware.com [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of David Ward Lambert Sent: Monday, November 26, 2012 11:59 PM To: programming Subject: Re: [Jprogramming] count iterations I learned much j tonight. My unnecessary extended precision crushed my memory. swops=: ((|.@:{. , }.)~ {.)^:a: (,. _1 + ! >./@:(#@swops@A. >:)&i. ])&> >:i.10 &> is the same, in this case, as "0 . Where you have (! hook&i. ]) I had orepeated i. . Beautiful work! On Tue, 2012-11-27 at 03:16 +0000, programming-requ...@forums.jsoftware.com wrote: > 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. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm