summaryrefslogtreecommitdiff
path: root/gcd.lisp
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-07 09:58:51 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-07 12:50:34 +0200
commitcdb159c137a82fd9756300dd6d1cba68f509b606 (patch)
tree38a2a3aeaff826ca06d2655c0c7772076b10a662 /gcd.lisp
parent2d27a4fbe3d9c8386c5477ac67a129ecba2c3ec7 (diff)
downloadgcd-cdb159c137a82fd9756300dd6d1cba68f509b606.tar.gz
lisp: no recursion
Diffstat (limited to 'gcd.lisp')
-rw-r--r--gcd.lisp6
1 files 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))