Advertisement
Guest User

Prime Number Checker

a guest
Sep 14th, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////
  2. // M. Quartz (Second Life - Fri Sep 14, 2018)
  3. // Since I'm too lazy to manually check if a number is
  4. // a prime or not, why not let lsl check for me:
  5.  
  6. // Create a prim in-world and drop this script in.
  7. // Use channel 22 and type a number in public
  8. // chat such as "/22 100" without quotes.
  9.  
  10. // Okay. If your number happens to be a prime
  11. // This script will say so. If your number happens
  12. // to NOT be a prime, the script will display a list
  13. // of all existing factors of that number in question.
  14.  
  15. // NOTE: The bigger the number, the longer
  16. // this takes, so go easy and keep it
  17. // under 3 digits lest wait!
  18. //
  19. ////////////////////////////////////////////////////////////
  20. #define int         integer
  21. #define str         string
  22. #define print0(a)   llOwnerSay(a)
  23.  
  24. int NO_PRIME;
  25.  
  26. default
  27. {
  28.     state_entry()
  29.     {
  30.         llListen(22,"",NULL_KEY,"");
  31.     }
  32.     listen(int C, str N, key I, str m)
  33.     {
  34.         if (llGetOwnerKey(I) == llGetOwner())
  35.         {
  36.             if ((int)m)
  37.             {
  38.                 int e;
  39.                 int x;
  40.                 while ((++x)<(int)m)
  41.                 {
  42.                     int y; ++e;
  43.                     while ((++y)<(int)m)
  44.                     {
  45.                         if ((e*y) == (int)m)
  46.                         {
  47.                             NO_PRIME = TRUE;
  48.                             print0("Found a factor at: "+(str)e+" * "+(str)y);
  49.                         }
  50.                     }
  51.                 }
  52.                 if (NO_PRIME)
  53.                 {
  54.                     NO_PRIME = FALSE;
  55.                     print0("Therefore "+"\""+m+"\" is NOT a prime number.");
  56.                 }
  57.                    
  58.                 else print0("No Factors found: "+"\""+m+"\" is a prime number.");
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement