in reply to Re: Unable to Understand grep and hash use for prime no.
in thread Unable to Understand grep and hash use for prime no.
In this case, the example is simply trying to show that results can be cached. As you say, we could reduce storage cost a lot and speed a little by using an array, string, or vector. Though one has to be careful with that as a single input of (for example) 1e18 will work fine with the hash but blow up with the other methods.
It turns out using a module (e.g. ntheory) for is_prime() is easier and faster overall anyway. No need to spend time on sieving, caching, memoize, etc. for these small sizes. But looking at the full context for this code, this is completely backwards -- he's using primality as a simple test vehicle to show caching.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unable to Understand grep and hash use for prime no.
by anonymized user 468275 (Curate) on Aug 07, 2015 at 14:15 UTC | |
by danaj (Friar) on Aug 08, 2015 at 06:18 UTC |