I have always been fascinated with prime numbers. The simple fact that every single number can be broken down into them but they can’t be broken down anymore always was intriguing to me. Their importance in encryption and that there is no formula (yet, although I believe there never will be) to reliably calculate new prime numbers also fueled this fascination.
So from the beginning for programing exercises I tasked myself with I created programs that were calculating prime numbers. But usually I stopped at some point after getting them to work a little because the process of calculating prime numbers is a bit let’s say memory consuming. However this time I actually took it so far that the calculated prime numbers are saved into a .txt file and then read from that at the next start of the program.
This little program obviously has little to no applicable uses since average computers are just not equipped to calculate large numbers of big prime numbers in a reasonably fast way. But maybe for whatever reason one of you needs a list of medium sized prime numbers for whatever reason. If that is the case feel free to use my program to calculate them, or use the provided list, although I don’t guarantee, that it is fully correct since it was partially calculated with earlier versions of the program. As far as I can judge the numbers seem to be in order and complete, though. I just can’t be asked to check 1 million + numbers manually.
Why am I sharing this here:
As a rather unexperienced coder I am sure I can benefit from the experience and opinions of individuals more accustomed to coding. I am simply hoping for some feedback on how to improve the code and my coding skills in general.
About the program:
Current Version: 1.3.1
– Calculating prime numbers
– Saving prime numbers into data base
– Reading prime numbers from data base
– Check whether certain number is a prime number
– Feature to continuously calculate prime numbers until stopped by user
– Checking data base for errors and clearing these
On first use the program creates the “PrimeNumbers.txt” file with the numbers 2 and 3 saved into in the same directory as it is located. It then or at each restart reads from this data base to include previously calculated prime numbers into a list, which then can either be read from or is used to calculate new prime numbers. The amount of prime number calculated in one sitting is manually chosen by the user. The newly calculated prime numbers are then saved into the .txt file created prior.
– Graphical User Interface (I have started the work on this but currently I am working on other optimizations)
The link leads to a Google Drive folder which contains the current version of the .exe file, the source code as .cs file and the PrimeNumbers.txt file with currently 12,000,000 calculated prime numbers (date: 04.05.2017).
– fixed source code regarding usage of “GoTo”.
– added “Test” function to test if any number is a prime number.
– minor source code clean up.
– added “Procedural” function which lets the program calculate numbers until it is stopped by the user.
– added a feedback for how many prime numbers have been found by using the “Procedural” function after ending it.
– source code clean up.
– Added “Scan” function which scans databases for errors and removes them.
– Fixed multiple minor bugs, that led to the program crashing when an unknown command was typed.
– Optimized calculation to be much faster. (Before it took me 3 seconds to calculate 200 prime numbers on my computer at around 3,000,000 numbers in storage, after I calculated 1,000,000,000 in 54 seconds.) The optimization was possible due to a to me formerly unknown property of prime numbers: the first number each prime number disqualifies is it’s square.
– Code Cleanup: I have moved snippets of codes, that were not needed in the Main method into sub methods and even created a few new ones to make it look better.
– Added a display for the time needed to perform calculations, the scan and loadind the data base.h
– When using the tool to continuously calculate prime numbers a problem might occur after long periods of time (or lots of prime numbers calculated).
– Is there a way to more efficiently save the data base onto the hard drive to make loading time and saving faster?
Thank you for reading and if you find a bug you can keep it. No obviously I am happy about each bug reported and fixed.
See you around,