This is missing a few divisors. It seems Skip's original method would be difficult to beat. It's O(n) in time and space. You could improve space complexity by doing a simple loop, but as far as I can see there are no shortcuts, and the best way is to just "brute force" it.
Sent from BlueMail On Apr 25, 2020, 5:35 AM, at 5:35 AM, 'Mike Day' via Programming <[email protected]> wrote: >I think this is near to the approved way: > > (*/"1@:>:@(_& q:))24 360 4711 >8 24 4 > >Mike > >Sent from my iPad > >> On 24 Apr 2020, at 21:13, Hauke Rehr <[email protected]> wrote: >> >> I now have an answer for the number of results: >> >> */ >: +/"1 (=/~ ~.) q: 4711 >> 4 >> */ >: +/"1 (=/~ ~.) q: 42 >> 8 >> >> I hesitate using =/~ (it’s actually deprecated) >> but I wouldn’t know a better way in this case >> >> >>> Am 24.04.20 um 21:09 schrieb Skip Cave: >>> I have used the wrong terminology. I want to find all the positive >integer >>> *divisors* of an integer n (not just primes) which includes 1 and >the >>> integer. >>> Here's a brute force verb I wrote: >>> div=:3 : 'a#~0=(a=.1+i.y)|y' >>> Test it: >>> div each 40+i.5 >>> │1 2 4 5 8 10 20 40│1 41│1 2 3 6 7 14 21 42│1 43│1 2 4 11 22 44│ >>> However my div verb is inefficient, slow, and runs out of memory >quickly on >>> larger integers. Is there a way to take advantage of J's prime >factoring >>> verb q: to more efficiently find and/or count *all* positive >divisors (not >>> just primes) of a large (>1e7) integers? >>> Skip >>> Skip Cave >>> Cave Consulting LLC >>> Skip Cave >>> Cave Consulting LLC >>>> On Fri, Apr 24, 2020 at 1:31 PM Roger Hui ><[email protected]> wrote: >>>> See https://code.jsoftware.com/wiki/Essays/Factorings >>>> >>>> >>>> >>>> On Fri, Apr 24, 2020 at 11:29 AM Skip Cave ><[email protected]> >>>> wrote: >>>> >>>>> I want to find all the integer factors of a positive integer, >>>>> which includes 1 and the integer. >>>>> Here's a brute force verb I wrote: >>>>> fac=:3 : 'a#~0=(a=.1+i.y)|y' >>>>> >>>>> Test it: >>>>> >>>>> fac each 40+i.5 >>>>> >>>>> │1 2 4 5 8 10 20 40│1 41│1 2 3 6 7 14 21 42│1 43│1 2 4 11 22 44│ >>>>> >>>>> >>>>> However my fac verb is inefficient, slow, and runs out of memory >quickly >>>> on >>>>> larger integers. Is there a way to take advantage of J's prime >factoring >>>>> verb q: to more efficiently find and/or count *all* positive >factors (not >>>>> just primes) of a large (>1e7) integers? >>>>> >>>>> >>>>> Skip >>>>> >>>>> >>>>> Skip Cave >>>>> Cave Consulting LLC >>>>> >---------------------------------------------------------------------- >>>>> For information about J forums see >http://www.jsoftware.com/forums.htm >>>>> >>>> >---------------------------------------------------------------------- >>>> For information about J forums see >http://www.jsoftware.com/forums.htm >>>> >>> >---------------------------------------------------------------------- >>> For information about J forums see >http://www.jsoftware.com/forums.htm >> >> -- >> ---------------------- >> mail written using NEO >> neo-layout.org >> >> >---------------------------------------------------------------------- >> For information about J forums see >http://www.jsoftware.com/forums.htm >---------------------------------------------------------------------- >For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
