A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Prime Number in Mathematica page! Here, you'll find the source code for this program as well as a description of how the program works.
(* Code *)
(* This is provided by a Mathematica built-in PrimeQ. Only a function to provide the 'user interface' is needed: *)
primeNumberMain = s \[Function] Module[
{e = "Usage: please input a non-negative integer"},
Catch[
Replace[
PrimeQ@
(* convert string to integer, or throw *)
If[StringMatchQ[s, DigitCharacter ..],
FromDigits[s],
Throw[e]],
{False -> "Composite", True -> "Prime"}]]];
(* Valid Tests *)
Print /@ primeNumberMain /@ {
"0",
"1",
"2",
"4",
"7",
"4011",
"3727"
};
(* Invalid Tests *)
primeNumberMain[""]
primeNumberMain["a"]
palindromicNumberMain["6.7"]
palindromicNumberMain["-7"]
Prime Number in Mathematica was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.