After making a script to run through all the 11 digit prime numbers, I realised it ran excruciatingly slow. To make it just that lot better, I decided to import to Delphi then back via a plguin. It has 3 things to fill in - Number, which is the number you want to check (int64), divisible which is a var int64 and holds the number that Number can be divided by (if it's not prime) and lastly Debug (boolean) which outputs a lot of text with larger numbers (says what number it is currently testing, which number it is dividing Number by and the 2 numbers I use for the comparison, which conists of checking if Round(a)=a. The function then outputs a boolean, with true meaning it is prime and false meaning it's not. I'll probably remove the Debug bit as I just used that for making sure it worked completely, but not 100% sure yet.
Also, it's the same plugin as found in my '11 digit prime number' thread.
Edit: Tried without the debug and it run quite a lot faster, so I've made a new compact version. Enjoy!
Edit2: Added source code.
Code:library CheckPrimePlugin_small; uses FastShareMem, SysUtils, Classes, Windows, Graphics; {$R *.res} type TSCARPlugFunc = record Name: string; Ptr: Pointer; end; TOneStrProc = procedure(s: string); var Writeln: TOneStrProc; function CheckPrime(number: Int64; var divisible: Int64): Boolean; stdcall; var i,ii: Int64; a,b: Extended; begin ii:= Trunc(Sqrt(StrToFloat(IntToStr(number))))+2; i:= 2; Result:= True; repeat a:= number/i; b:= Round(a); if(a=b) then begin Result:= False; divisible:= i; Break; end; i:= i+1; until(i>=ii); if(number=2) then Result:= True else if(number=1) then Result:= False; end; function GetFunctionCount(): Integer; stdcall; export; begin Result := 1; end; function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; stdcall; begin case x of 0: begin ProcAddr := @CheckPrime; StrPCopy(ProcDef, 'function CheckPrime(number: Int64; var divisible: Int64): Boolean;'); end; else x := -1; end; Result := x; end; procedure SetFunctions(Funcs: array of TSCARPlugFunc); stdcall; var i: Integer; begin for i := 0 to Length(Funcs) - 1 do if Funcs[i].Name = 'Writeln' then Writeln := Funcs[i].Ptr; end; //*************************** // Don't change below this exports GetFunctionCount; exports GetFunctionInfo; exports SetFunctions; end.




Reply With Quote


Make a RS script and apply already







). It takes 5 minutes+ for the scar script to check 10000000001, while the plugin takes under a second, now that's quick 
