From cdb159c137a82fd9756300dd6d1cba68f509b606 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Mon, 7 Nov 2022 09:58:51 +0200 Subject: lisp: no recursion --- gcd.lisp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gcd.lisp b/gcd.lisp index 89ee997..79852a9 100644 --- a/gcd.lisp +++ b/gcd.lisp @@ -5,9 +5,9 @@ ; # sbcl --script gcd.lisp 121 22 33 (defun gcd2 (a b) - (if (= b 0) - a - (gcd2 b (mod a b)))) + (loop while (/= b 0) do + (psetq a b b (mod a b)) + finally (return a))) (defun gcdn (n &rest ns) (reduce #'gcd2 ns :initial-value n)) -- cgit v1.2.3