Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////
- // M. Quartz (Second Life - Fri Sep 15, 2018)
- // Updated to act more robust.
- //
- // 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 4 digits lest wait!
- //
- ////////////////////////////////////////////////////////////
- #define int integer
- #define str string
- #define lst list
- #define print0(a) llOwnerSay(a)
- default
- {
- state_entry()
- {
- llListen(22,"",NULL_KEY,"");
- }
- listen(int c, str n, key i, str m)
- {
- if (llGetOwnerKey(i) == llGetOwner())
- {
- if ((int)m)
- {
- print0("Please wait. This may take awhile..");
- lst t;
- int x; int e;
- while ((++x)<(int)m)
- {
- int y; ++e;
- while ((++y)<=x)
- if ((e*y) == (int)m)
- t += ["("+(str)e+" * "+(str)y+")"];
- }
- if (t != [])
- {
- int n = llGetListLength(t);
- print0("Multiplication factors found: "+(str)n+"\n"+llDumpList2String(t, "\n")
- +"\nTherefore "+"\""+m+"\" is NOT a prime number."); t = [];
- }
- else
- print0("No factors found: "+"\""+m+"\" is definitely a prime number.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement