Easier fac3=: [: ~.@(],*)/ 1 ,~q:
fac3 160 1 5 2 10 4 20 8 40 16 80 32 160 and more efficient 5 ts'fac3"0 >:[EMAIL PROTECTED]' 0.00082320317 34752 5 ts'fac2"0 >:[EMAIL PROTECTED]' 0.0012543979 33408 5 ts'fac1"0 >:[EMAIL PROTECTED]' 0.0011410222 33408 R.E. Boss > -----Oorspronkelijk bericht----- > Van: [EMAIL PROTECTED] [mailto:programming- > [EMAIL PROTECTED] Namens Roger Hui > Verzonden: maandag 7 januari 2008 19:04 > Aan: Programming forum > Onderwerp: Re: [Jprogramming] Fitting factors of positive integers > > Two defns that use only the monad q: > > fac1=: , @ > @ (*/&.>/) @ (<@(1,*/\)/.~) @ q: > fac2=: */"1 @ (>@,) @ { @ (<@(1,*/\)/.~) @ q: > > > > ----- Original Message ----- > From: Roger Hui <[EMAIL PROTECTED]> > Date: Monday, January 7, 2008 8:24 > Subject: Re: [Jprogramming] Fitting factors of positive integers > To: Programming forum <[email protected]> > > > f=: */ .^"1 (#: i.@(*/))@:>: > > factors=: f/@(__&q:) > > > > factors 160 > > 1 5 2 10 4 20 8 40 16 80 32 160 > > factors 144 > > 1 3 9 2 6 18 4 12 36 8 24 72 16 48 144 > > factors 97 > > 1 97 > > factors 1 > > 1 > > > > Or, to name a well-known subexpression used therein, > > odometer=: #: i.@(*/) > > f=: */ .^"1 odometer@:>: > > > > > > > > ----- Original Message ----- > > From: neville holmes <[EMAIL PROTECTED]> > > Date: Sunday, January 6, 2008 21:12 > > Subject: [Jprogramming] Fitting factors of positive integers > > To: [email protected] > > > > > I was trying to put myself to sleep last night by > > > working out (tacit) ways to list the distinct factors > > > of positive integers. Is there a better way than > > > simply sieving through all the candidates less > > > than or equal to the square root of the number ? > > ... > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
