From 94a69e7b765e5df93b21ffef763a8c27c69228c2 Mon Sep 17 00:00:00 2001 From: Pekka Laiho Date: Sat, 17 Oct 2020 14:18:16 +0700 Subject: [PATCH] use inc/dec for factorial --- mad/fact.mad | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mad/fact.mad b/mad/fact.mad index c791644..7f45a63 100644 --- a/mad/fact.mad +++ b/mad/fact.mad @@ -1,7 +1,7 @@ ;; Functions to calculate factorial ;; Recursive version, not tail call optimized -(def recFact (fn (n) (if (< n 2) 1 (* n (recFact (- n 1)))))) +(def recFact (fn (n) (if (< n 2) 1 (* n (recFact (dec n)))))) ;; Apply version -(def applyFact (fn (n) (if (< n 2) 1 (apply * (range 1 (+ n 1)))))) +(def applyFact (fn (n) (if (< n 2) 1 (apply * (range 1 (inc n))))))