A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Factorial in Mathematica page! Here, you'll find the source code for this program as well as a description of how the program works.
(* Code *)
(* The Mathematica built-in Factorial essentially provides the required behavior;
so the only code needed is the 'user interface' to make it look a little more
like a Unix command-line tool: *)
factorialMain = Catch[
(* convert string to integer, or throw *)
If[
StringMatchQ[#, DigitCharacter ..],
FromDigits[#]!,
Throw["Usage: please input a non-negative integer"]]] &;
(* Valid Tests *)
Print /@ factorialMain /@ {"0", "1", "4", "8", "10"};
(* Note that Mathematica (as far as I know) doesn't impose an upper limit on computations: *)
factorialMain["10000"]
(* Invalid Tests *)
factorialMain[""]
factorialMain["asdf"]
factorialMain["-1"]
Factorial 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.