Large Factorials in LISP

/ Published in: Lisp
Save to your folder(s)

Large factorials are easy to do in LISP, although a number above (2000!) may crash it. I designed this because of an online post from a mathematician talking about the number 1000! . Code like this is difficult to write in C-like languages, but a snap in LISP, as the following code demonstrates.

Copy this code and paste it in your HTML
  1. (defun factorial(x)
  2. (cond ((zerop x) 1)
  3. ('T (* x (factorial (1- x)))) ))
  5. (factorial 1000)

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.