icol1=: # - +/@(+./\)@(1&=) See also: http://www.jsoftware.com/jwiki/Essays/Collatz_Conjecture
----- Original Message ----- From: John Randall <[EMAIL PROTECTED]> Date: Tuesday, October 28, 2008 16:24 Subject: Re: [Jprogramming] Index of first one in columns To: Programming forum <[email protected]> > Dan Bron wrote: > > John wrote: > >> icol=:(] i. 1:)"1@:|: > >> Is there a better way (that avoids the transpose)? > > > Thanks for the response: I am glad I am not missing anything obvious. > > Perhaps you can make a suggestion to avoid how this arises for > me, which > is in iterating functions on a list of values. > > For example, here is the Collatz function: > > collatz=: -:`(>:@(3&*))`1: @. (1&= + 2&|) > > If I now say > > (collatz"0)^:(i.10) >:i.20 > 1 2 3 4 5 6 7 8 9 10 11 12 13 > 14 15 16 17 18 19 20 > 1 1 10 2 16 3 22 4 28 5 34 6 40 7 > 46 8 52 9 58 10 > 1 1 5 1 8 10 11 2 14 16 17 3 20 22 > 23 4 26 28 29 5 > 1 1 16 1 4 5 34 1 7 8 52 10 10 11 > 70 2 13 14 88 16 > 1 1 8 1 2 16 17 1 22 4 26 5 5 > 34 35 1 40 7 44 8 > 1 1 4 1 1 8 52 1 11 2 13 16 16 17 > 106 1 20 22 22 4 > 1 1 2 1 1 4 26 1 34 1 40 8 8 > 52 53 1 10 11 11 2 > 1 1 1 1 1 2 13 1 17 1 20 4 4 > 26 160 1 5 34 34 1 > 1 1 1 1 1 1 40 1 52 1 10 2 2 > 13 80 1 16 17 17 1 > 1 1 1 1 1 1 20 1 26 1 5 > 1 1 40 40 1 8 52 52 1 > > the iterations run down the columns. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
