On Fri, Oct 3, 2008 at 10:43 AM, Dan Bron <[EMAIL PROTECTED]> wrote: > Pick n > 0 and odd, multiply by three, > add one, cast out all factors of two, > cook 'til (d)one. > > Can you improve this verb?
(0,}.)&.(_&q:)@(1 3&p.) ^:a: 7 > Can you generalize it to cast out all (positive integer) > factors of N where N isn't neccesarily prime > (e.g. 4&castOut )? For the general case, I might replace (0,}.)&.(_&q: y with N (<.((<:@[EMAIL PROTECTED] + (- *)) ))/@,:~&.:(_&q:) y but an explicit definition might be more efficient? > PS: A secondary nit to pick: I don't like the way I pick > "n > 0 and odd". Your domain is odd, positive integers. You can produce no meaningful result for values outside your domain, and I see no significant value in extending this domain to include even, positive integers. However, I would use (+ 2 | <:)@? instead of using 1 + ? to generate a random number within your domain. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
