Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////
- // M. Quartz: Check an input number to determine whether
- // its a prime or a composite.
- ////////////////////////////////////////////////////////////
- #define int integer
- #define str string
- #define lst list
- #define print(a) llOwnerSay(a)
- ////////////////////////////////////////////////////////////
- // Keeping the time, size short and modest:
- #define MCR_LIMIT 1500
- //
- ////////////////////////////////////////////////////////////
- default
- {
- state_entry()
- {
- llListen(22, "", llGetOwner(), "");
- }
- listen(int c, str n, key i, str m)
- {
- if ((int)m < MCR_LIMIT) // capped
- {
- print("Scanning integer: This may take awhile..");
- lst t; // fishing net
- int z = (int)m; // typecast
- /////////////////////////////////////////////////////////////////////////////////
- int x; // rows up
- while (++x <z)
- {
- int y; // columns across
- while (++y <=x)
- if (x*y == z) // capture
- t += ["("+(str)x+" * "+(str)y+")"]; // collect
- }
- /////////////////////////////////////////////////////////////////////////////////
- if (t != []) // caught anything?
- {
- int n = llGetListLength(t); // how many
- print("Factors found: "+(str)n+"\n"+llDumpList2String(t, "\n")+ // list
- "\nTherefore integer \""+m+"\" is a composite."); t = []; // clear
- } else
- print("No factors found: Therefore integer \""+m+"\" is a prime."); // prime
- m = ""; // tidy
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement