in reply to Re: Perl Not Releasing Memory
in thread Perl Not Releasing Memory

There are faster ways to decide this problem, as well. I'm no mathematician, but your algorithm is dividing by all odd factors between 3 and sqrt(x); this can be improved by dividing by all *prime* factors between 3 and sqrt(x).

Since you're already finding all these numbers, just use dynamic programming-- when you find a prime, hash it for later reference. Then in your loop just go through the keys of your hash.

Replies are listed 'Best First'.
Re: Re: Re: Perl Not Releasing Memory
by Limbic~Region (Chancellor) on Jul 02, 2003 at 14:45 UTC
    Anonymous Monk,
    As tilly would say, I am a displaced mathematician. I realize the inefficiency of the algorithm and I appreciate you pointing it out. In fact, the code itself could have been made a lot more concise by sacrificing readability. I was just trying to help the new monk out. I figured it was easy enough to understand and modify for their purposes.

    Cheers - L~R