This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:summer2017:cprog:projects:pnc2 [2017/07/08 12:38] – [Approximating array size] wedge | haas:summer2017:cprog:projects:pnc2 [2017/07/08 12:47] (current) – [Approximating array size] wedge | ||
---|---|---|---|
Line 310: | Line 310: | ||
... we would see that the 32nd prime is 131. For the Sieve of Eratosthenes to successfully work in this case, we'd need an array size of at least 132 (if we do the standard mapping of array element to actual number, where element 0 would correspond with the number 0, and element 131 would correspond with number 131; 0-131 = 132 elements). | ... we would see that the 32nd prime is 131. For the Sieve of Eratosthenes to successfully work in this case, we'd need an array size of at least 132 (if we do the standard mapping of array element to actual number, where element 0 would correspond with the number 0, and element 131 would correspond with number 131; 0-131 = 132 elements). | ||
- | But that number isn't immediately known (indeed, the nature of the distribution of prime numbers is the subject of considerable mathematical exploration, | + | But that number isn't immediately known (indeed, the nature of the distribution of prime numbers is the subject of considerable mathematical exploration, |
And without this knowledge of the largest prime in the desired quantity, our sieve implementation (with the requirements as I have specified) is sort of at a standstill. | And without this knowledge of the largest prime in the desired quantity, our sieve implementation (with the requirements as I have specified) is sort of at a standstill. | ||
Line 323: | Line 323: | ||
<code bash 1> | <code bash 1> | ||
+ | # clear the screen | ||
clear | clear | ||
+ | |||
+ | # loop for a powers of 2 progression 32-4194304 (inclusive) | ||
for((qty=32; | for((qty=32; | ||
+ | |||
+ | # display the quantity lead-in information | ||
printf "[%7s] %7sth prime: " " | printf "[%7s] %7sth prime: " " | ||
+ | | ||
+ | # obtain the last/ | ||
value=$(./ | value=$(./ | ||
+ | |||
+ | # display it, along with calculating its approximate multiplier | ||
printf "%8s (x%s)\n" | printf "%8s (x%s)\n" | ||
done | done | ||
Line 460: | Line 469: | ||
The execution of the programs is short and simple- grab the parameters, do the processing, produce the output, and then terminate. | The execution of the programs is short and simple- grab the parameters, do the processing, produce the output, and then terminate. | ||
+ | Based on specifications, | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | 5 7 11 13 17 | ||
+ | 0.000080 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | And (shift the lower bound, but still count out 32 primes): | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 | ||
+ | 0.000087 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | And of course the same for the 3 variants, and the same error message reporting if invalid values are given. | ||
====Performance changes==== | ====Performance changes==== | ||
You may notice a change with the sieves as compared to the other algorithms you've implemented with respect to performance- there will likely be a lower bound of performance, | You may notice a change with the sieves as compared to the other algorithms you've implemented with respect to performance- there will likely be a lower bound of performance, |