SRL Archive - Other Scripts

"Insert prime 11 digit number to continue" solver


mixster

2008-03-05 14:38:17

Don't we all hate it when we get asked for that prime 11 digit number and we just can't think of one off the top of our heads? Well hate no more, with the prime 11 digit number checker! Has full Int64 support (after a lot of me getting pissed off) so you can get just about any prime number if you wish to change the script! Furthermore, if you run it for long enough, you actually get a full list of all the 11 digit prime numbers! Now, without further rambling, I present to you, the 11 digit prime number checker!
Version 3P(lugin) is now available and uses the attatched delphi plugin to speed up the checking greatly.
program ElevenDigitPrimeNumberChecker;
var
i,d: Int64;
aPNum: array of Int64;
li,li2,ii: Integer;
begin
ClearDebug;
ClearReport;
ChangeReportWidth(200);
li:=0;
li2:=7;
i:= 10000000001;
repeat
if(CheckPrime(i,d,False))then
begin
SetArrayLength(aPNum,GetArrayLength(aPNum)+1);
aPNum[GetArrayLength(aPNum)-1]:= i;
AddToReport(Int64ToStr(i)+' is prime');
end
else
begin
Writeln(Int64ToStr(i)+' is not prime - divisable by '+Int64ToStr(d));
end;
i:=i+2;
until(i>=100000000000);
i:= 0;
ClearDebug;
ClearReport;
repeat
Writeln(Int64ToStr(aPNum[ii])+' is prime, yay!');
Inc(ii);
until(ii>=GetArrayLength(aPNum));
end.
V2 (plugin) got released quickly as I added Sqrt compatibility making it run much much faster on actual prime numbers.

You can change the boolean in CheckPrime to show extra debug text (written from the dll and consists of what number it is currently dividing and the result of the number divided by i and the number rounded), though it will seriously clog up the debug box. Lastly, I will be improving the 3P version to make it look nice etc. but in the mean time, the script works well.

~ R.I.P mr.kleans signature ~

Harry

2008-03-05 15:35:59

10000000004 is a prime 11 digit number, yay!
10000000019 is a prime 11 digit number, yay!
10000000033 is a prime 11 digit number, yay!
10000000058 is a prime 11 digit number, yay!
10000000061 is a prime 11 digit number, yay!


NICE! Great work, *PM's to Mr.klean to change his siggy ;)*

Edit: Add a Wait(1); every once in a while, my CPU lagged to 100% when I forgot to stop it :duh:

mixster

2008-03-05 15:53:29

Uggh, after doing a bit more testing (mainly after noticing 10000000004 can be divided by 2) I noticed that the silly extendeds don't have enough decimal places/general places, so it rounds it a bit, making it inaccurate :( If only they thought about adding that 1 extra float value when making delphi, then I wouldn't ahve this problem. Ahwell, every challenge is fun to beat.
Edit: I now have nearly fixed it - only problem is that my int64's are playing up again (I think) so are proving to be troublesome when checking against the extended value (as it only seems to be going up to the normal int boundaries)

Mr.Klean

2008-03-05 21:18:32

Hmm, well I just have to let you know that I hate you and I hope your script suddenly doesn't work and fries your computer. Then the flames from the burning carcass of your computer simultaneously lights you on fire and you get full engulfed in flames. (Has anyone been fully on fire? Its gotta be SO hot!) Then when you heal from your burns and you go swimming, you dive off the diving board, and while you are at the bottom of the pool freaking out because you think you are going to drown, someone pours oil all over the surface of the water. And when you find a spot with no fire and you surface, a big dude just punches you in the face and screams "GET BACK IN THE FIREY WATER!" Then you slowly drown in the water dieing the ultimate worst death.

Time for a new sig…. :(

Jason2gs

2008-03-05 21:32:33

From: mr.klean
Hmm, well I just have to let you know that I hate you and I hope your script suddenly doesn't work and fries your computer. Then the flames from the burning carcass of your computer simultaneously lights you on fire and you get full engulfed in flames. (Has anyone been fully on fire? Its gotta be SO hot!) Then when you heal from your burns and you go swimming, you dive off the diving board, and while you are at the bottom of the pool freaking out because you think you are going to drown, someone pours oil all over the surface of the water. And when you find a spot with no fire and you surface, a big dude just punches you in the face and screams "GET BACK IN THE FIREY WATER!" Then you slowly drown in the water dieing the ultimate worst death.


Ouch.

Dan Cardin

2008-03-05 21:41:59

why only do "i := i + 1;" do + 2 because no even numbers can be prime(-2)

Harry

2008-03-05 21:48:52

From: Dan Cardin
why only do "i := i + 1;" do + 2 because no even numbers can be prime(-2)


Really? I am pretty sure I saw a even prime somewhere…

bullzeye95

2008-03-05 22:56:10

2 is the only even prime number.

mixster

2008-03-06 02:04:53

It doesn't work for now mr.klean, so you're safe (thank the limitation of trunc/round and their longint output :()… for now… And I might as well use +2 even though it will only save a few seconds after doing it all (as it divides by 2 first), but I guess when you're going through 89999999999 numbers, it will help in the long run.
Also, you can bet your pony that the next version will be even cooler and run a lot smoother (didn't add waits, but the Writeln's etc. slow it down, so it shouldn't take over), not to mention even add more awesome functions/procedures.

Dan Cardin

2008-03-06 06:58:20

From: Hy71194
Really? I am pretty sure I saw a even prime somewhere…


if you were mentioning 2 then the
-2
meant no even unless you count 2 or minus 2 :)

otherwise they are divisible by 2

Mr.Klean

2008-03-06 13:39:01

Hey, you want to go out for pizza and some sex? What, you don't like pizza?



My sig = win now.


@Mix, well I don't hate you now then, when it does work I shall hope you die the ultimate death.

mixster

2008-03-06 13:40:00

I've decided to give up, mainly because extended values are giving me errors (as the values I'm using are so big), so I'm just gonna have it find all 10 digit prime numbers (so far it runs properly and smoothly, but haven't tested the higher values, as it runs quite slowly when it has to process so many numbers).

program PrimeNumberChecker;
const
FullWrite = False;
var
a: extended;
sTime,time: integer;

function TrimSingleDecimal(a: extended): extended;
begin
Result:= a*10;
Result:= Round(Result);
Result:= Result/10;
end;

function Divide(a,b: extended): extended;
begin
Result:= a*10;
Result:= Result/b;
Result:= Result/10;
end;

function CheckNumber(number: int64): boolean;
var
i,ii: int64;
iii: integer;
a,b: extended;

begin
ii:= Trunc(Sqrt(number)) + 1;
Result:= True;
i:= 2;
repeat
for iii:= 0 to 8 do
begin
if(GetDebugLine(iii)='Currently checking '+Int64ToStr(number)) then
Break;
end;
a:= Divide(number,i);
if(FullWrite)then
ReplaceDebugLine(iii+1,'Currently dividing by '+Int64ToStr(i)+'('+FloatToStr(a)+', '+FloatToStr(Trunc(a))+')');
if((not(FullWrite)) and (Time<=GetSystemTime))then
begin
Time:= GetSystemTime+5000;
ReplaceDebugLine(iii+1,'Been checking for '+IntToStr(Round((time-sTime)/1000))+'s');
end;
if((Round(a+0.5))=(Trunc(a))) then
begin
Result:= false;
ReplaceDebugLine(iii+1,'It can be divided by '+Int64ToStr(i)+'('+FloatToStr(a)+', '+FloatToStr(Trunc(a))+'), =(');
Break;
end;
i:= i+1;
Wait(100);
until(i>=ii);
if(Result)then
ReplaceDebugLine(iii+1,'It is a prime number, hurrah!');
end;

procedure CheckAllNumbers;
var
i: int64;
ii,iii: integer;
numbers: array of int64;
begin
i:= 100000001;
iii:= 0;
repeat
ReplaceDebugLine(iii*3,'Currently checking '+Int64ToStr(i));
Inc(iii);
if(iii>=4) then
iii:= 0;
if(CheckNumber(i)) then
begin
SetArrayLength(numbers,GetArrayLength(numbers)+1);
numbers[GetArrayLength(numbers)-1]:= i;
ReplaceDebugLine(9,Int64ToStr(numbers[GetArrayLength(numbers)-1])+' is a prime 11 digit number, yay!');
end;
i:= i+2;
until(i>=10000000000)
for ii:= 0 to GetArrayLength(numbers)-1 do
Writeln(Int64ToStr(numbers[i])+' is a prime 11 digit number, yay!');
end;

begin
time:= GetSystemTime+5000;
sTime:= GetSystemTime;
ClearDebug;
Writeln('');Writeln('');Writeln('');
Writeln('');Writeln('');Writeln('');
Writeln('');Writeln('');Writeln('');
CheckAllNumbers;
end.

Also, 10000000001 is an 11 digit prime number ;)

Harry

2008-03-06 14:59:29

*Bugs Freddy to make 'divtrue' to do divide like MS Calculator would, with float values :)*

mixster

2008-03-06 15:07:55

I would prefer if he made a built-in 'list all the prime 11 digits' function ;)

Harry

2008-03-06 15:11:49

From: mixster05
I would prefer if he made a built-in 'list all the prime 11 digits' function ;)


Lol, I hit quote with the "I wish he made div or / work", but that would be nice too.

I think he made div auto round so it will be easier so people won't have to do Round(dv(x)); all the time when they want to use div, and use an integer, not a floating integer.

mixster

2008-03-06 15:54:41

Only problem is I'm pretty sure it still spits it out as an extended so gives a type mismatch (will check that quickly) [edit] it spits it out as a rounded down int - which is annoying in it's own respect [/edit] and I changed it because I'm still not 100% sure if it does it in all versions, so it might be that it was just added in 3.14 (checking how div or / rounds isn't my priority when a new scar version comes out). Still, I'm hoping to transfer the whole script into delphi then import it into scar again, as lets face it - if it isn't scar, then no one cares :p I do wish that my download would hurry up though, at the rate it's going I'm gonna have to get it ready in an hour and a half at most otherwise I'll have to wait till tomorrow morning or maybe the afternoon.

Edit: For anyone who cares, written the delphi code and just need a builder for it to make the dll and it should be done and fully converted and functional (even made it accept a range so it can be used outside of just 11 digit prime numbers and stil have the separate checker to see if it's a prime number, so both can be useful). Also, if you have a delphi builder/compiler, send me a pm and I'll send you the script, so you can be nice and build the dll for me :p

MASSIVE edit2: Fixed the script and even developed an awesome new RoundToDecimal function and also my own divide to save a bit of time after realising scar has auto-trunc when dividing actual numbers (doesn't happen with var's). (Neither of them are included in here, but I still made them while working on it).
program PrimeNumberChecker;
const
FullWrite = True;
var
sTime,time: integer;

function CheckNumber(number: int64): boolean;
var
i,ii: int64;
iii: integer;
a,b: extended;

begin
ii:= Trunc(Sqrt(number)) + 1;
Result:= True;
i:= 2;
repeat
Wait(1);
for iii:= 0 to 8 do
begin
if(GetDebugLine(iii)='Currently checking '+Int64ToStr(number)) then
Break;
end;
a:= number;
a:= a/i;
if(FullWrite)then
ReplaceDebugLine(iii+1,'Currently dividing by '+Int64ToStr(i)+'('+FloatToStr(a)+', '+FloatToStr(Trunc(a))+') - '+IntToStr(ii-i)+' numbers left to check');
if((not(FullWrite)) and (Time<=GetSystemTime))then
begin
Time:= GetSystemTime+5000;
ReplaceDebugLine(iii+1,'Been checking for '+IntToStr(Round((time-sTime)/1000))+'s');
end;
if((Round(a+0.5))=(Trunc(a))) then
begin
Result:= false;
ReplaceDebugLine(iii+1,'It can be divided by '+Int64ToStr(i)+'('+FloatToStr(a)+', '+FloatToStr(Trunc(a))+'), =(');
Break;
end;
i:= i+1;
Wait(100);
until(i>=ii);
if(Result)then
ReplaceDebugLine(iii+1,'It is a prime number, hurrah!');
end;

procedure CheckAllNumbers;
var
i: int64;
ii,iii: integer;
numbers: array of int64;
begin
i:= 10000000001;
iii:= 0;
repeat
ReplaceDebugLine(iii*3,'Currently checking '+Int64ToStr(i));
Inc(iii);
if(iii>=4) then
iii:= 0;
if(CheckNumber(i)) then
begin
SetArrayLength(numbers,GetArrayLength(numbers)+1);
numbers[GetArrayLength(numbers)-1]:= i;
ReplaceDebugLine(9,Int64ToStr(numbers[GetArrayLength(numbers)-1])+' is a prime 11 digit number, yay!');
end;
i:= i+2;
until(i>=100000000000)
for ii:= 0 to GetArrayLength(numbers)-1 do
Writeln(Int64ToStr(numbers[i])+' is a prime 11 digit number, yay!');
end;

begin
time:= GetSystemTime+5000;
sTime:= GetSystemTime;
ClearDebug;
Writeln('');Writeln('');Writeln('');
Writeln('');Writeln('');Writeln('');
Writeln('');Writeln('');Writeln('');
CheckAllNumbers;
end.

Set FullWrite to false if it's running to slowly or you don't want to see what number it's on etc. otherwise, enjoy! (except mr.klean who now has to hate me :()

Harry

2008-03-07 21:37:31

Sweeeeet! (post on post one ;))

Edit: Meh… -_- Do I need to run this for a few years to get a prime number? :p It takes forever to even complete 10000000001… :(

Currently checking 10000000001
Currently dividing by 508(19685039.3720472, 19685039) - 99493 numbers left to check








Edit2: Owned. http://en.wikipedia.org/w/index.php?title=Prime_number&action=edit§ion=16 Largest prime known is 2^32,582,657(-1).

mixster

2008-03-08 05:48:04

How is it owned? I was just trying to make 11 digit prime numbers as I saw mr.kleans signature around and wondered… anyway, I'm pretty sure the largest known prime number would be
1000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000
000000000000000(etc.)1 as every 3 (I think) 0's, the number is prime, so just put an infitinte amount of 0's inbetween two 1's and you're sorted (though I guess that's more a theoretical largest known prime number).
And yes I know it's slow, trying to put it into a nice delphi script, only problem is I've only got a dodgy one that doesn't even have StrToInt in it :( I really do need to get a better one, but Delphi 6 or 7 don't seem to be downloadable from anywhere, so I'm stuck with my dodgy version of Turbo Delphi.
Also, why does your link take me to the edit page? lol
Edit: Yay found a delphi 7 download, so it should be full delphi-a-nised by the end of the day (as last time I checked I couldn't fluently code delphi, ahwell) so cheers all round! Also, I'm still not sure if I want it to be a delphi .exe or a scar plugin? I guess I might as well make it a plugin, but still not sure.
Edit2: Made the plguin, now just making sure it all works.

jon_071

2008-03-11 16:54:30

Well, that above theory is completely wrong…

for instance,1000000000001 / 23 =4347826087 …

http://primes.utm.edu/largest.html

google it!


If you want to see the largest prime #, go here–

http://www.mersenneforum.org/txt/43.txt

it takes some time to load, even though the page is all text.

mixster

2008-03-11 17:00:57

It's a theory an old maths teacher taught me (can't remember the exact theory for it, though I remember it beeing every three 0's add to it, it's prime), so I was pretty sure it wouldn't work, though I thought it may be worth mentioning it and applying it. Anyway, did you actually go through the numbers 3 to 23 to test the number or did you use my plugin? Not to put any more pressure on your post, but I can have a list of like 500,000 11 digit prime numbers in a few minutes if you want to test them too :)
Also, for anyone who still cares, nearly finished the fully plugin-a-nised version of this script, though I still doubt it will be able to get through all 90 billion numbers without crashing. I'm really just debugging it and making sure it works effectively and properly, so you can expect it soon.

Mr.Klean

2008-03-11 21:49:13

Well its pretty useless. As in time wise.

Suggestion: When it does find something divisible make sure it does not check the number that its multiplied by so it is faster. Otherwise its a waste. Must be a better way to do it.

I will look around online and ask my Calculus teacher to see if he knows a quicker way to find primes.

mixster

2008-03-12 07:09:43

I wouldn't say it is completely useless timewise, I mean there are 90 billion numbers to check (45 billion really as it divides by 2 1st so gets rid of all the even numbers) but there's still a lot to check. Anyway, I've got a full delphi plugin for it at the moment and it uses a set of base numbers (ranging from 2 to the end integer's square root rounded + 1) that gets set in about 50-150 ms (my pc is old and has quite a lot of fluctuations in terms of performance) and has improved the speed greatly with the larger numbers. I've also thrown in an output integer so you can choose how often to output prime numbers found so far (also helps keep the debug box more clear as it outputs them more accross than down). I would release it now, except it keeps running into small bugs, so until it works properly I'll just have to keep improving it.