Developing Problems - Prime Numbers

One day I was talking to a friend, and we got into a point of the conversation we all get sometimes, calculating prime numbers. I told him about how a self-aware joke program I was making, called ALFRED 2, one day I’ll write about it, and how if you asked him to calculate all prime numbers, he would start and then tell you to do it yourself. And while we were talking about it, he then said, yeah, but, it's impossible to calculate all prime numbers isn't it? And then I explained a very easy way of doing it: You use the prime numbers you have as fuel, if you have a lot of them you will get big prime numbers, and if you have a very few you will get small ones. I started giving the program 1 and 2, but then because of some technical reasons I gave it 3 too. So what the program did was using a counter, which started on the last prime number you gave it and try to divide every number by all the prime numbers it has. If it couldn't be divided by any of them, it would include that number on the list. So I created a program that could calculate the first 500000 numbers on less than 30 minutes on a fairly good computer.

But that was the problem, I could only calculate 500000 numbers, not one more, I don't really know what the problem was, maybe the compiler, maybe my computer, but arrays could only work up to 500000 numbers, and if you wanted more, the program would stop working. I thought of many ways of fixing this, I thought of creating a file to store all the prime numbers, and that way the program could also start from another computer without having to start all the way back from one. But that was fairly complicated, so I think I just left it aside for a while. I'm sorry Prime-Number v1.2, but getting numbers from data is so messy…

Anyway, this past few days I've been thinking of ways of improving my code, like if it's trying to tell if 5001 is prime, and it's trying to divide it for a number bigger than its half, let's say 3337 (I don't know if its prime) to put it on the prime list. Because you don't have to try to divide 13 by 11, when you pass, 6.5 you already know its prime. I don't know…

I think I wanna go back to Prime-Number, so if you guys wanna help me please leave a comment, and I will upload it, so we can get to earn money by calculating prime numbers… Just kidding (or am I?).

Comentarios