On 5 May 2008, at 17:46, [EMAIL PROTECTED] wrote:
> I do need to use large sets of data because my current definitive
> test for primes relies on being able to % against all primes up to
> and including the square root of the number I'm testing. For this
> reason a list won't work. I'm currently looking into faster
> algorithms (Fermat's little theorem and The Euclidean algorithm)
> although I'm pretty sure I won't be able to switch to a list
> (coincidentally whats the difference between a list a stack and a
> queue?). I really do have to optimize now as I left my program
> running over night and I had only found the primes between 0 and
> 700000. I'll look into use the tie::hash a bit more once I have a
> better algorithm (and I have used it a bit more at work).
Stacks are lists that you append to and remove from at a single end.
Queues are lists that you append to at one end, and remove from at the
other. They're different uses for lists.
I'm sure I don't know enough detail about your work, but I'm not sure
why what you describe precludes using a list?
e.g. some perl-ish pseudocode - assume @known_primes is a list of
primes you've found, next_test_case gives you a new number to test
given the last test and the biggest known prime, and your test routine
is my_test - does something like the following pseudoperl roughly fit
your description ?
# get a new test candidate based on our state
while( $test_case = next_text_case($test_case,$known_primes[-1] ){
# iterate over the primes we've found so far, shoving the square root
on the end of the iteration list
foreach $prime (@known_primes, sqrt($test_case) ){
# if we find a prime, stick it on the end of the list and get
a new candidate
push @known_primes, $test_case && break if
my_test($test_case,$prime);
}
}
etc.
I'm still not saying you definitely *should* use an array though. Just
trying to offer some interesting avenues for further exploration.
--
Regards,
Colin M. Strickland
_______________________________________________
BristolBathPM mailing list
[email protected]
http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm