Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////
- // M. Quartz (Second Life - Fri Sep 14, 2018)
- // Since I'm too lazy to manually check if a number is
- // a prime or not, why not let lsl check for me:
- // Create a prim in-world and drop this script in.
- // Use channel 22 and type a number in public
- // chat such as "/22 100" without quotes.
- // Okay. If your number happens to be a prime
- // This script will say so. If your number happens
- // to NOT be a prime, the script will display a list
- // of all existing factors of that number in question.
- // NOTE: The bigger the number, the longer
- // this takes, so go easy and keep it
- // under 3 digits lest wait!
- //
- ////////////////////////////////////////////////////////////
- #define int integer
- #define str string
- #define print0(a) llOwnerSay(a)
- int NO_PRIME;
- default
- {
- state_entry()
- {
- llListen(22,"",NULL_KEY,"");
- }
- listen(int C, str N, key I, str m)
- {
- if (llGetOwnerKey(I) == llGetOwner())
- {
- if ((int)m)
- {
- int e;
- int x;
- while ((++x)<(int)m)
- {
- int y; ++e;
- while ((++y)<(int)m)
- {
- if ((e*y) == (int)m)
- {
- NO_PRIME = TRUE;
- print0("Found a factor at: "+(str)e+" * "+(str)y);
- }
- }
- }
- if (NO_PRIME)
- {
- NO_PRIME = FALSE;
- print0("Therefore "+"\""+m+"\" is NOT a prime number.");
- }
- else print0("No Factors found: "+"\""+m+"\" is a prime number.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement