Anonymous user
Greatest common divisor: Difference between revisions
m
→{{header|Common Lisp}}: style
m (→{{header|J}}) |
m (→{{header|Common Lisp}}: style) |
||
Line 596:
Here is an implementation using the do macro. We call the function <code>gcd2</code> so as not to conflict with <code>common-lisp:gcd</code>.
<lang lisp>(defun
(do () ((zerop b) (abs a))
(shiftf a b (mod a b))))</lang>
Line 602:
Here is a tail-recursive implementation.
<lang lisp>(defun
(if (zerop b)
a
(gcd2 b (mod a b))))</lang>
The last implementation is based on the loop macro.
<lang lisp>(defun
(loop for x = a then y
and y = b then (mod x y)
until (zerop y)
finally (return x)))</lang>
=={{header|Component Pascal}}==
BlackBox Component Builder
|