using builtin q:

I get correct results using

   /:~ ~.@, ((*/)@#"1~ #:@:i.@(2&^)@#) 1,q: 4711
1 7 673 4711
   /:~ ~.@, ((*/)@#"1~ #:@:i.@(2&^)@#) 1,q: 42
1 2 3 6 7 14 21 42

less brute force but it’s just a first attempt


Am 24.04.20 um 20:28 schrieb Skip Cave:
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


--
----------------------
mail written using NEO
neo-layout.org

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to