Hi, all

...further feverish notes to self...

Joel Neely wrote:
> 

I believe that using

    zero? foo

is the tiniest bit faster than

    foo = 0

but that's probably insignificant...

> 
> One last hack (left as an exercise for the reader... ;-) is to
> save all primes previously found, and use only known primes as
> trial divisors...
> 

Of course, I should have said that the last hack is to save all
prime *trial*divisors* previously found, since the memoized list
of divisors must be ordered and without gaps.  To atone for my
poor phraseology, I'll submit the following for scrutiny (and,
as always, corrections, tweaks, etc.)


use [d] [
    d: [2 3 5 7]
    prime?: func [p /local c s] [
        if found? find d p [return true]
        foreach v d [
            if zero? p // v [return false]
            if v * v > p  [return true ]
        ]
        either zero? s: (c: 2 + last d) // 3 [
            c: c + 2  s: 4
        ][
            s: s + s
        ]
        while [c * c <= p] [
            if prime? c [
                append d c
                if zero? p // c [return false]
            ]
            c: c + s: 6 - s
        ]
        return true
    ]
]


-jn-

-- 
; sub REBOL {}; sub head ($) {@_[0]}
REBOL []
# despam: func [e] [replace replace/all e ":" "." "#" "@"]
; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"}
print head reverse despam "moc:xedef#yleen:leoj" ;
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to