A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Palindromic 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 PalindromeQ. Only a function to provide the 'user interface' is needed: *)
palindromicNumberMain = s \[Function] Module[
{e = "Usage: please input a non-negative integer"},
Catch[
Replace[
PalindromeQ@
(* convert string to integer, or throw *)
If[StringMatchQ[s, DigitCharacter ..],
FromDigits[s],
Throw[e]],
{False -> "false", True -> "true"}]]];
(* Valid Tests *)
Print /@ palindromicNumberMain /@ {
"7",
"2442",
"232",
"5215",
"521"
};
(* Invalid Tests *)
palindromicNumberMain[""]
palindromicNumberMain["a"]
palindromicNumberMain["-5"]
palindromicNumberMain["5.41"]
Palindromic 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.