Results 1 to 11 of 11

Thread: Prime Checker

  1. #1
    Join Date
    Mar 2008
    Location
    Indiana
    Posts
    192
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Prime Checker

    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.



    SCAR Code:
    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.

  2. #2
    Join Date
    Mar 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Very Original... I like it a lot! Wonderful first script
    The one and only Durza998

  3. #3
    Join Date
    Mar 2008
    Location
    Indiana
    Posts
    192
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Here would be the original pascal code.
    Attachment

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

  4. #4
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Nice try
    Take a look at this to see a different method:
    SCAR Code:
    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.

  5. #5
    Join Date
    Mar 2008
    Location
    Indiana
    Posts
    192
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    @ 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.)

    Anyways what is the integer limit in scar?

  6. #6
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I see... An integer goes from -2147483648 to 2147483647

  7. #7
    Join Date
    Mar 2008
    Location
    Indiana
    Posts
    192
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Another question

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

    It would help increase the range of script.

  8. #8
    Join Date
    Oct 2006
    Location
    finland, helsinki
    Posts
    2,501
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

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

    Code:
    • Narcle: I recall Jukka releasing a bunch of scripts like this before... Its how he rolls I think. rofl
    • Solarwind: Dude, you are like... t3h s3x.
    • Hy71194: JuKKa you're a machine! You released 3 scripts in 10 minutes! :O
    • benjaa: woah.... Jukka is the man Guildminer pwns all
    • NaumanAkhlaQ: And JuKKa Is my Her0!

  9. #9
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by smithsps View Post
    Another question

    Is there a long integer variable type, like in pascal?
    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
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  10. #10
    Join Date
    Mar 2008
    Location
    Indiana
    Posts
    192
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ooo... Im going to have to try this.... Thx Narcle

  11. #11
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HP Checker
    By faster789 in forum RS3 Outdated / Broken Scripts
    Replies: 4
    Last Post: 02-16-2009, 08:55 PM
  2. Metroid Prime 3: Corruption
    By n3ss3s in forum Gaming
    Replies: 1
    Last Post: 11-28-2007, 03:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •