RosettaCodeData/Task/Factorial/Slope/factorial-1.slope
2023-07-01 13:44:08 -04:00

5 lines
191 B
Text

(define factorial (lambda (n)
(cond
((negative? n) (! "Negative inputs to factorial are invalid"))
((zero? n) 1)
(else (reduce (lambda (num acc) (* num acc)) 1 (range n 1))))))