SICP Exercise 1.24 (Fermat Method)
Exercise 1.24. Modify the timed-prime-test procedure of exercise 1.22 to use fast-prime? (the Fermat method), and test each of the 12 primes you found in that exercise. Since the Fermat test has (log n) growth, how would you expect the time to test primes near 1,000,000 to compare with the time needed to test primes near 1000? Do your data bear this out? Can you explain any discrepancy you find?
SOLUTION
Fermat Method
The code and tests are here.
Observations
============
the O(log n) growth can be seen. For every 10 fold increase of the number, the
time taken is increasing by the same roughly constant amount.
There are some discrepancies (see Excel sheet). These are probably due to
other stuff happening on the computer
SOLUTION
Fermat Method
The code and tests are here.
Observations
============
the O(log n) growth can be seen. For every 10 fold increase of the number, the
time taken is increasing by the same roughly constant amount.
There are some discrepancies (see Excel sheet). These are probably due to
other stuff happening on the computer
Comments
Post a Comment