PlummersSoftwareLLC / Primes

Prime Number Projects in C#/C++/Python
https://plummerssoftwarellc.github.io/PrimeView/
2.46k stars 572 forks source link

bit allocation should be dynamic #412

Closed jdemchuk closed 3 years ago

jdemchuk commented 3 years ago

https://github.com/PlummersSoftwareLLC/Primes/blob/2c7bbf93d8c157db547d9dac2937d38c188399c0/PrimeGo/solution_1/main.go#L100

initBitArray := make([]bool, 1e6)

the array size is hard coded to 1,000,000 elements. Should this by dynamic and allow for 10, 100, 1000 ...? Also, in Go, a bool type requires 1 byte for memory allocation, so each element in initBitArray is using 8 bits, and your output tag would need to specify '8' for the storage flag.

rbergen commented 3 years ago

I think this is a good question. I would say that in the end, every solution defines the sieve size as a constant at some point, and this solution just does it twice. Once when creating the bit array, and once when passing the sieve size to the Sieve class' constructor. To be honest, I think the main issue with this solution, from a faithfulness perspective, is that it allocates the bit array only once. That should happen with the loop to make it happen every time, which is required as per the guidelines

rbergen commented 3 years ago

Opened #431 to address the point in my previous comment.

rbergen commented 3 years ago

Merged #431. Considering the 8 bits per prime, the lack of a tag means that it is currently marked as "unknown", which is a valid state in the code and therefore not an issue as such. Both mean that the solution will not be included in Dave's leaderboard comparison. Of course, if a PR is opened to add a bits=8 tag to the solution's output, I would be happy to consider it.