SRL Archive - First Scripts

Prime Checker


smithsps

2008-03-02 19:48:18

I wrote this program originally in pascal so i had to make a couple of changes.
I am not sure what the maximum number is for a integer in scar.
Letters, #s with decimals, and #s over the maximum number, WILL NOT WORK!
It does compile so…

Please post suggestions or point out errors that i have made.

Version 2 released
I added the boolean and increased the maximum to about 10,000,000,000,000.(10 trillion).

Thanks for Durza998, bullzeye95, JuKKa, Narcle for helping me out.



Program PrimeNumberChecker;
{Made by Smithsps}

var
A1, A2, A3 : int64;
CN, CN2, CN3, CN4, UEN : int64;
Z1, Z2, Z3 : string;
end1 : string;
Prime : boolean;

Procedure Prime1;
begin
if (Prime = False) then
begin
Z1 := inttostr(CN4);
Z2 := inttostr(CN3);
writeln('Your number is not prime');
writeln('Divider was: ' + Z1);
writeln('It goes in it '+ Z2 + ' times.');
end;
if (Prime = True) then
begin
writeln('Congratulations, your number was Prime.');
end;
end;

Procedure Mod1;
begin
A1 := UEN div CN;
A2 := A1 * CN;
A3 := UEN - A2;
end;

Procedure Check;
begin
CN := 1;
CN2 := UEN - 1;
repeat
CN := CN + 1;
Mod1;
if (A3 = 0) then
begin
Prime := False;
end;
until (CN2 = CN) or (Prime = False);
CN4 := CN;
CN3 := UEN div CN4;
ClearDebug;
if (UEN = 2) then
Prime := True;
end;

Procedure Begining;
begin
Prime := True;
ClearDebug;
Z3 := readln('Please enter the number you want to check.');
UEN := strtoint64(Z3);
ClearDebug;
end;

Procedure Ending;
begin
writeln('');
writeln('Thank you for using my script. Made by Smithsps');
end1 := readln('Type "Exit" to quit. Type nothing or anything else to continue.');
ClearDebug;
end;

Procedure MasterScript;
begin
repeat
Begining;
Check;
Prime1;
Ending;
until (end1 = 'Exit') or (end1 = 'exit');
end;

begin
MasterScript;
end.

durza998

2008-03-02 20:05:25

Very Original… I like it a lot! Wonderful first script

smithsps

2008-03-02 20:16:49

Here would be the original pascal code.
Attachment

@ durza998
Thanks, but I have wrote some code before. :)

bullzeye95

2008-03-02 21:20:14

Nice try :)
Take a look at this to see a different method:
program New;

function IsPrime(Num: Integer): Boolean;
var
S, I: Integer;
begin
S:= Floor(Sqrt(Num));
for I:= 2 to S do
if(Num mod I = 0)then break;
Result:= I = (S + 1);
end;

begin
writeln(booltostr(IsPrime(13)));
end.

smithsps

2008-03-03 06:58:13

@ Bullzeye
I had something like that the first time I made the script. But the mod function built into pascal was not powerful enough so, I had to make my own way. (Which I think that I made.):spot:

Anyways what is the integer limit in scar?

bullzeye95

2008-03-03 07:45:15

I see… An integer goes from -2147483648 to 2147483647 :)

smithsps

2008-03-03 17:00:54

Another question

Is there a long integer variable type, like in pascal? :confused:
I did not see in the scar manual.

It would help increase the range of script.

JuKKa

2008-03-04 01:10:12

instead of using strings like that use "Boolean" true/false.

Narcle

2008-03-04 01:17:57

From: smithsps
Another question

Is there a long integer variable type, like in pascal? :confused:
I did not see in the scar manual.

It would help increase the range of script.


I believe int64 for a range up to 2^64… umm 18446744073709551616

smithsps

2008-03-04 06:45:47

Ooo… Im going to have to try this…. Thx Narcle:)

bullzeye95

2008-03-04 07:47:31

Actually the range is -9223372036854775808 to 9223372036854775807
Though that's not really much of a difference, they're both huge numbers :rolleyes: