http://qs321.pair.com?node_id=1126040


in reply to Re^6: Number functions.. primes (ugly code runs faster)
in thread Number functions I have lying around

Very nice. About 1.5x faster, better looking code, though 2x memory use.

Addendum: Can you put it on RosettaCode or let me know it's ok to put there? Everything there gets covered by the GNU FDL so I don't want to put there without some sort of permission. More code improvements are also welcome :)

  • Comment on Re^7: Number functions.. primes (ugly code runs faster)

Replies are listed 'Best First'.
Re^8: Number functions.. primes (ugly code runs faster)
by Anonymous Monk on May 08, 2015 at 01:20 UTC

    Regarding memory use: the result array footprint probably outweighs the sieve for limits up to 1014.

    Re: code. m//gogo is the sole bit of artistic liberty (or wishful thinking) and can be shortened to just //g. And sure, you're welcome to it, to work on it or repost it. An anonymonk couldn't say no, anyhow.

      On memory footprint, it's important if using it for just the count where there is no array. Also for cases where we hold onto the string for later use in walking primes without resieving or storing the array. However, even doubling the string memory still results in >10x less memory than the array versions.

      Thanks re posting. Given the licensing, I thought it was prudent to ask.