NOTE: Comment your code, and verify it works for “breaking cases” i.e. 0! = 1.
(+ 2 3 4)
(defun factorial(x)
(setq total 1)
(while (> x 0)
(setq total (* total x))
(decf x))
total)
(factorial 4)
(factorial 8)
(factorial 0)
When the number gets over 60 something it causes wrap around. None of the numbers I have tried have caused my computer to freeze.
It goes through a supplied list and calls a function using each item of the list as an input.
(setq cool-list '(2 5 22 15))
(defun square (x)
(* x x))
(mapcar 'square cool-list)
(defun count-numbers (x) ; Will return the sum of all of the numbers from 0 to the number input.
(setq total 0)
(while (> x 0)
(incf total x)
(decf x))
total)
(count-numbers 10)