in reply to Unable to Understand grep and hash use for prime no.
(1) only prime factors need to be tested as factors and so test factors (all of them used per test) should also have their results kept in the lookup, so the lookup storage belongs to the function 'is_prime' (could be a package variable) rather than held at the scope shown in the snippet.
(2) hash access slows disproportionately whereas this lookup could just be an array. That array could be packed down to one bit per element for the most efficient storage, given that it has only boolean values. Lookup (and registration) can be achieved without unpacking from that using bit operators such as '<<' and '&', thereby winning on processing as well as storage.
One world, one people
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unable to Understand grep and hash use for prime no.
by davido (Cardinal) on Aug 04, 2015 at 14:21 UTC | |
by anonymized user 468275 (Curate) on Aug 04, 2015 at 18:26 UTC | |
|
Re^2: Unable to Understand grep and hash use for prime no.
by danaj (Friar) on Aug 05, 2015 at 08:21 UTC | |
by anonymized user 468275 (Curate) on Aug 07, 2015 at 14:15 UTC | |
by danaj (Friar) on Aug 08, 2015 at 06:18 UTC |