[CSC 330] Project 3 Pitfall

Andrew J. Pounds pounds_aj at mercer.edu
Thu Nov 21 01:49:35 EST 2024


When working on the collatz project many of you are going to be tempted 
to create a massive array to hold, for example, all of the sequence 
lengths for the numbers over you integer range.  I am encouraging you 
NOT to do this because I could easily cause you code to fail if I picked 
a range of [1,2000000000]. Yes -- I might do that.

Here is what I recommend -- maintain table of numbers and sequence 
lengths.  You could do this parallel arrays of 10 elements (numbers, and 
sequence lengths) or some sort of array structure where you are keeping 
up with ten numbers and their sequence length.  After each sequence 
length you compute see if you can update the numbers in your table (i.e. 
-- is the new sequence length longer than anything else in your table?)

This type of coding, where you are using a minimal amount of memory and 
relying just on integer calculations and comparisons should be very fast.

-- 
*/Andrew J. Pounds, Ph.D./*
/Professor of Chemistry and Computer Science/
/Director of the Computational Science Program/
/Mercer University/
/1501 Mercer University Drive, Macon, GA 31207 /
/(478) 301-5627/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc330/attachments/20241121/280d0cda/attachment.htm>


More information about the csc330 mailing list