An interesting idea, which also turned out to be slow in the current Julia
version (0.3.0):

There are 8 coprimes to 30, so one can reduce the data needs by only
keeping the gaps to the next coprimes in an array (g), and use the last
three bits of a counter for circular indexing. (Assuming the first divisor
to try this way is at least 7). Unfortunately, Julia uses 1-base indexing,
so we have to add 1 to the numbers formed by the last three bits of the
counter, an extra operation. Array indexing also checks for out-of-range
indices. We can save these steps by the Julia command for the next trial
divisors:

d += unsafe_load(f,(j+=1)&7)

(the address of the gaps array is incremented by 1 to get pointer f).

The initialization is done outside of the factoring function by:
~~~
const g = int8([6 4 2 4 2 4 6 2])
const f = pointer(g)+1
const j0 = [7 0 0 0 0 0 0 0 0 0 1 0 2 0 0 0 3 0 4 0 0 0 5 0 0 0 0 0
6][PRIMES3[end]%30]
~~~

Reply via email to